OkHttp身份验证器是否处理403错误?

huangapple go评论76阅读模式
英文:

Does okhttp authenticator handle 403 error?

问题

我正在使用 Okhttp Authenticator 来更新我的 JWT 令牌。但是存在一个问题,即当我从后端收到 401 响应时,会调用 authenticate() 方法。但是当我收到 403 响应表示令牌过期时,authenticate() 方法不会被调用。是否有关于 authenticator() 方法工作原理的好的主题,或者我们是否可以手动调用它?还有一个主要问题是,它是否处理 403 响应?

英文:

I'm using Okhttp Authenticator for updating my JWT tokens. But there is a problem, that the authenticate() method is called, when I'm getting 401 from backend. But when I'm getting 403 - token expired, the authenticate() method doesn't get called. Is there any good topic about how the authenticator() method works or can we call it manually? And also the main question - does it handle 403 response?

答案1

得分: 3

你可以添加自己的拦截器来捕获403错误,更新令牌并重试。\n\n实际上,这就是我项目中的这个拦截器所做的 https://github.com/yschimke/okurl/blob/5163436f8bcb2526e8be7b72d59d99a9db433848/src/main/kotlin/com/baulsupp/okurl/authenticator/RenewingInterceptor.kt

英文:

You can add your own interceptor to catch the 403, renew the token and retry.

It's essentially what this interceptor in my project does https://github.com/yschimke/okurl/blob/5163436f8bcb2526e8be7b72d59d99a9db433848/src/main/kotlin/com/baulsupp/okurl/authenticator/RenewingInterceptor.kt

huangapple
  • 本文由 发表于 2020年4月6日 22:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/61062057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定