Can I use both of Basic and Bearer in Authorization header?

Viewed 1185

I implemented JWT token for API Authorization. Every request that required authorization is sent with JWT token in Authorization header like this: Authorization: Bearer <token>. Everything is clear for me about JWT token except login request.

I just want to use Authorization: Basic <credentials> where login request. I suppose sending username and password as plain text seems not good. But I'm not sure.

Is it okay to use Basic <credentials> on login request and then use Bearer <token> on other request?

1 Answers

Good morning. It is best practice to create a method and invoke that using POST call. Pass the Login Credentials as an object to the post method. The login method should return the JWT token. Once you receive the JWT token, then onwards please use bearer XXXXXXXX.

Example:

[AllowAnonymous]
[HttpPost]
public IActionResult CreateToken([FromBody]LoginModel login)
{
    // Your logic to Authenticate and Generate the JWT TOKEN.
      return response;
}
Related