- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3
add authentication to requests if required #13
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
base: multiplatform-client
Are you sure you want to change the base?
add authentication to requests if required #13
Conversation
|  | ||
| protected fun HttpRequestBuilder.addAuthentication(apiKeyAuths: List<String>, basicAuths: List<String>, bearerAuths: List<String>, oAuths: List<String>) { | ||
| for (name in apiKeyAuths) { | ||
| val auth = apiKeyAuth[name] ?: throw IllegalStateException("ApiKeyAuth \"$name\" was configured, but not found") | 
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.
These had the pretty good reason to error on invalid schemas, so I'd like to keep them
| } | ||
| } | ||
| for (name in basicAuths) { | ||
| val auth = basicAuth[name] ?: throw IllegalStateException("HttpBasicAuth \"$name\" was configured, but not found") | 
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.
See above
| } | ||
| } | ||
| for (name in bearerAuths) { | ||
| val auth = bearerAuth[name] ?: throw IllegalStateException("HttpBearerAuth \"$name\" was configured, but not found") | 
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.
See above
| } | ||
| } | ||
| for (name in oAuths) { | ||
| val auth = oAuth[name] ?: throw IllegalStateException("OAuth \"$name\" was configured, but not found") | 
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.
See above
| I think I forgot to remove the TODO or so, can't remember, but it seems workable so 🤷♂️ | 
| 
 Yeah, but the commented-out code for requests, like: addAuthentication("Authorization")did not match the method signature of the extension in  protected fun HttpRequestBuilder.addAuthentication(apiKeyAuths: List<String>, basicAuths: List<String>, bearerAuths: List<String>, oAuths: List<String>)So i changed it to: protected fun HttpRequestBuilder.addAuthentication(vararg auths: String)and i only left only the last error check since it looks for the added authentication methods under all schemes (basic, api, bearer and oauth) and only throws an error if none was matched. | 
| Well in that case I probably forgot to fix the signature of the function call and that's why it was still commented out, shouldn't be too hard to fix, you can look at an example at the declaration of the authentications. | 
Currently the call to
addAuthenticationfor requests is commented-out with a 'TODO' comment...I'm not sure if that implementation is what you had in mind but it does work for my use-case where I
use 'basic auth' to fetch a 'api-key' for further requests.
Anyway, it does need to be implemented, otherwise no auth headers are added to requests.