Prepare a headless storefront sign-in page

If your storefront is not built on Commerce Storefront powered by Edge Delivery Services, implement this contract on your sign-in and create-account pages. The pages complete the OAuth 2.0 request with the Adobe Commerce GraphQL API.

  1. Read the request parameters from the query string of the sign-in page:

    table 0-row-3 1-row-3 2-row-3 3-row-3 4-row-3 5-row-3 6-row-3 7-row-3
    Parameter Required Description
    response_type Yes Must be code.
    client_id Yes ID of the OAuth 2.0 client registered in the Commerce Admin.
    redirect_uri Yes Must exactly match a redirect URI registered for the client.
    code_challenge Yes PKCE code challenge.
    code_challenge_method Yes Must be S256.
    scope No Space-separated scopes. Without it, the client’s allowed scopes apply.
    state No Returned unchanged to the client.
  2. Keep the parameters while the shopper signs in or creates an account, for example in sessionStorage for the current browser tab. They contain no secret.

  3. Sign the shopper in as usual, for example with the generateCustomerToken mutation.

  4. Call the issueOauthAuthorizationCode mutation over HTTPS, with the customer token in the Authorization: Bearer header:

    code language-graphql
    mutation {
      issueOauthAuthorizationCode(input: {
        client_id: "<client_id>"
        redirect_uri: "<redirect_uri>"
        scope: "<scope>"
        state: "<state>"
        code_challenge: "<code_challenge>"
        code_challenge_method: "S256"
      }) {
        redirect_url
      }
    }
    
  5. Send the browser to redirect_url, for example with window.location.assign(). The URL carries code, state, and iss, or an OAuth 2.0 error that the agent handles. The code can be used once and expires after five minutes.

If the mutation returns a GraphQL error, do not redirect. Show the error to the shopper instead. This happens when the client or the redirect URI is not valid, the request does not use HTTPS, or the token is not a customer token.

To let shoppers see and remove the agents they linked, for example on the account page, use the customerOauthAuthorizations query and the revokeOauthAuthorization(client_id) mutation.

Next step next-step

Return to Set up shopper authentication and activate Shopper MCP.

recommendation-more-help
commerce-help-shopper-mcp