英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论