-
Notifications
You must be signed in to change notification settings - Fork 555
fix: Use okhttp3 Interceptor in place of Authenticator for network module #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| override fun authenticate(route: Route?, response: Response): Request? { | ||
| override fun intercept(chain: Interceptor.Chain): Response? { | ||
| val authorization: String? = authHolder.getAuthorization() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| val authorization: String? = authHolder.getAuthorization() | |
| val authorization = authHolder.getAuthorization() |
| } | ||
|
|
||
| single { RequestAuthenticator(get()) as Authenticator } | ||
| single { RequestAuthenticator(get()) as Interceptor } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to cast IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is giving same definition error if I do not cast.
| HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY) | ||
| ) | ||
| .authenticator(get()) | ||
| .build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have not added the interceptor here. What's the point then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
0d7a60e to
0e3a04e
Compare
| val authorization = authHolder.getAuthorization() | ||
| val original = chain.request() | ||
| val request = original.newBuilder() | ||
| .header("Authorization", authorization.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why toString?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is showing error while running Authorization == null and network module is not working. Because here authorization type is nullable String.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only run this if (!Utils.isEmpty), problem solved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
0e3a04e to
fd21da9
Compare
Fixes #1006