Search code examples
javaspring-bootspring-security

Securing Spring boot rest Api with basic and Bearer Auth At the same time


I'm trying to use both basic auth and bearer Token to authenticate the same Api using Spring boot.

Each one works fine until. I add the other. Does any one had the same problem before ?


Solution

  • The same endpoint cannot have both because the Authorization header needs to be either:

    Basic ksjskjskjskjksj
    

    or

    Bearer djhkdjhdkjhdkhdkjh.ldjldkjldkjl.ldkjldkjldkj==
    

    You need to intercept the outgoing call and conditionally add one or the other header.