How can I change token endpoint url in AuthenticationAPIClient

In AuthenticationAPIClient we have following method

    public fun token(
        authorizationCode: String,
        codeVerifier: String,
        redirectUri: String
    ): Request<Credentials, AuthenticationException> {
        val parameters = ParameterBuilder.newBuilder()
            .setClientId(clientId)
            .setGrantType(ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE)
            .set(OAUTH_CODE_KEY, authorizationCode).set(REDIRECT_URI_KEY, redirectUri)
            .set("code_verifier", codeVerifier)
            .asDictionary()
        val url = auth0.getDomainUrl().toHttpUrl().newBuilder()
            .addPathSegment(OAUTH_PATH)
            .addPathSegment(TOKEN_PATH)
            .build()
        val credentialsAdapter: JsonAdapter<Credentials> = GsonAdapter(
            Credentials::class.java, gson
        )
        val request = factory.post(url.toString(), credentialsAdapter)
        request.addParameters(parameters)
        return request
    }

How can I remove .addPathSegment(OAUTH_PATH) here as my token endpoint does not have this path segment.

Thanks
Anil

Hi @anil-k-s,

Welcome to the Auth0 Community!

In general, your token endpoint should point to the /oauth/token token URL. You mentioned that your token endpoint does not have this path segment.

I recommend ensuring the request looks something like the following:

curl --request POST \
  --url 'https://{yourDomain}/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=authorization_code \
  --data 'client_id={yourClientId}' \
  --data 'client_secret={yourClientSecret}' \
  --data 'code=yourAuthorizationCode}' \
  --data 'redirect_uri={https://yourApp/callback}'

(Reference: Call Your API Using the Authorization Code Flow)

I can see that you are trying to perform the Authorization Code flow. Which in Auth0, passes the authorization code to the /oauth/token endpoint to get your tokens.

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.