Olá
Vi que o instrutor implementou o seguinte código:
response?.addHeader("Authorization", "Bearer $token")
Entendi que o argumento Authorization
é como se fosse um identificador, mas o que seria o Bearer
? Não consegui captar exatamente o que é.
Código completo:
class JWTLoginFilter(
private val authManager: AuthenticationManager,
private val jwtUtil: JWTUtil,
): UsernamePasswordAuthenticationFilter() {
override fun attemptAuthentication(request: HttpServletRequest?, response: HttpServletResponse?): Authentication? {
val (username, password) = ObjectMapper()
.readValue(request?.inputStream, Credentials::class.java)
val token = UsernamePasswordAuthenticationToken(username, password)
return authManager.authenticate(token)
}
override fun successfulAuthentication(
request: HttpServletRequest?,
response: HttpServletResponse?,
chain: FilterChain?,
authResult: Authentication?
) {
val username = (authResult?.principal as UserDetails).username
val token = jwtUtil.generateToken(username)
response?.addHeader("Authorization", "Bearer $token") // <---- aqui
}
}