Hi, i'm running into an issue where the oauth auth...
# ktor
l
Hi, i'm running into an issue where the oauth authentication does not redirect to the authorization link when there is another authentication configured alongside it. The idea is that I want the block to first check if the user has a session on the web, and then if so use oauth to connect to the service its trying to access Here is my code
Copy code
routing {
    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()
            }
        }
    }
}
Copy code
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!
a
Nested
authenticate
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.