Search code examples
amazon-web-servicesamazon-cognitoauth0

Amazon Cognito: add custom parameters to authorize URL when using OIDC identity provider


As stated in the title, I would like to add a custom parameter to the /authorize URL to which Cognito redirects when working with a OIDC User Pool Identity Provider (in my case https://example.xx.auth0.com/authorize).

I found out you can specify an authorize URL through cloudformation but it cannot contain query parameters.

More details: Cognito is configured through Serverless (which uses Cloudformation under the hood):

Auth0IdentityProvider:
    Type: AWS::Cognito::UserPoolIdentityProvider
    Properties:
        UserPoolId:
            Ref: CognitoUserPool
        ProviderType: "OIDC"
        ProviderName: "Auth0"
        ProviderDetails:
            client_id: "xxxx"
            client_secret: "xxxx"
            attributes_request_method: "GET"
            oidc_issuer: "https://xxxx.xx.auth0.com"
            authorize_scopes: "openid profile email"
        AttributeMapping:
            email: "email"

When navigating to the Cognito hosted UI and selecting the Auth0 provider it redirects to the /authorize Cognito endpoint which in turn redirects to the /authorize Auth0 endpoint.

I need to add the connection parameter to Auth0's /authorize in order to bypass its UI and go straight to the social login but I haven't been able to find a way to do so.


Solution

  • Turns out that when configuring your Auth0 client you can specify the connection parameter and Auth0 will skip its UI for you, but it will only do that if the configured redirect_uri does not point to localhost.

    auth0 = await createAuth0Client({
        redirect_uri: window.location.origin,
        scope: "openid profile email offline_access",
        connection: "linkedin",
    });