Skip to content

Conversation

@fullkomnun
Copy link

@fullkomnun fullkomnun commented Feb 22, 2021

Currently the call to addAuthentication for 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.


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")
Copy link
Owner

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")
Copy link
Owner

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")
Copy link
Owner

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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@cromefire
Copy link
Owner

I think I forgot to remove the TODO or so, can't remember, but it seems workable so 🤷‍♂️

@fullkomnun
Copy link
Author

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 ApiClientBase:

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.

@cromefire
Copy link
Owner

cromefire commented Feb 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants