Lukas S
10/16/2022, 7:08 PMrouting {
authenticate(UserAuthentication.USER_SESSION) {
authenticate(OAUTH_NAME) {
ebayLogin()
}
}
}
authentication {
oauth(OAUTH_NAME) {
urlProvider = { System.getenv("EBAY_REDIRECT_URI") }
providerLookup = {
OAuthServerSettings.OAuth2ServerSettings(
name = "eBay",
authorizeUrl = "<https://auth.ebay.com/oauth2/authorize>",
accessTokenUrl = "<https://api.ebay.com/identity/v1/oauth2/token>",
requestMethod = <http://HttpMethod.Post|HttpMethod.Post>,
clientId = System.getenv("EBAY_CLIENT_ID"),
clientSecret = System.getenv("EBAY_CLIENT_SECRET"),
defaultScopes = listOf(
"<https://api.ebay.com/oauth/api_scope>",
),
accessTokenRequiresBasicAuth = true,
extraTokenParameters = listOf()
)
}
client = HttpClient(CIO) {
install(ContentNegotiation) {
json()
}
}
}
}
fun Route.ebayLogin() {
get("/ebay/login") {
// redirects to 'authorizeUrl' automatically
}
get("/ebay/login/callback") {
val principal = call.principal<OAuthAccessTokenResponse.OAuth2>()
// TODO: save token to database
call.respondRedirect("/ebay")
}
}
Thanks!Aleksei Tirman [JB]
10/18/2022, 10:49 AMauthenticate
routes are combined with “or” operator so the first authenticated route (UserAuthentication.USER_SESSION
) leads to successful authentication and the oauth
authentication is never executed. Unfortunately, there is no API to authenticate a client if all the authenticate
routes are resolved.