1 {"slug":"/references/auth/validateCallback","title":"validateCallback - Auth Module Reference","frontmatter":{"displayed_sidebar":"authReference","slug":"/references/auth/validateCallback","sidebar_label":"validateCallback"},"toc":[{"title":"Example","id":"example","level":2},{"title":"Parameters","id":"validatecallback-parameters","level":2},{"title":"Returns","id":"validatecallback-returns","level":2}],"blocks":[{"kind":"markdown","html":"This documentation provides a reference to the `validateCallback` method. This belongs to the Auth Module."},{"kind":"note","variant":"note","html":"You should only use this methods when implementing complex customizations. For common cases, check out [available workflows instead](/medusa-workflows-reference)."},{"kind":"markdown","html":"When authenticating users with a third-party provider, such as Google, the user performs an\naction to finish the authentication, such as enter their credentials in Google's sign-in\nform.\n\nIn those cases, you must create an API route or endpoint that's called by the third-party\nprovider when the user finishes performing the required action.\n\nIn that API route, you can call this method to validate the third-party provider's\ncallback and authenticate the user.\n\nLearn more about this authentication flow in [this guide](https://docs.medusajs.com/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow)."},{"kind":"heading","level":2,"text":"Example","id":"example"},{"kind":"markdown","html":"The following example is in the context of an API route, where\n`req` is an instance of the `MedusaRequest` object:\n\n```ts\nconst { success, authIdentity, error } =\n await authModuleService.validateCallback(\"google\", {\n url: req.url,\n headers: req.headers,\n query: req.query,\n body: req.body,\n protocol: req.protocol,\n } as AuthenticationInput)\n```"},{"kind":"heading","level":2,"text":"Parameters","id":"validatecallback-parameters"},{"kind":"typeList","sectionTitle":"validateCallback","types":[{"name":"provider","type":"`string`","description":"The ID of the provider to use to validate the callback.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerData","type":"[AuthenticationInput](/references/auth/interfaces/auth.AuthenticationInput)","description":"The data to pass to the provider to validate the callback.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"url","type":"`string`","description":"URL of the incoming authentication request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"headers","type":"`Record<string, string>`","description":"Headers of incoming authentication request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"`Record<string, string>`","description":"Query params of the incoming authentication request.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"body","type":"`Record<string, string>`","description":"Body of the incoming authentication request.\n\nOne of the arguments that is suggested to be treated in a standard manner is a `callback_url` field.\nThe field specifies where the user is redirected to after a successful authentication in the case of Oauth auhentication.\nIf not passed, the provider will fallback to the callback\\_url provided in the provider options.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"protocol","type":"`string`","description":"Protocol of the incoming authentication request (For example, `https`).","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"Returns","id":"validatecallback-returns"},{"kind":"typeList","sectionTitle":"validateCallback","types":[{"name":"Promise","type":"Promise&#60;[AuthenticationResponse](/references/auth/interfaces/auth.AuthenticationResponse)&#62;","optional":false,"defaultValue":"","description":"The details of the authentication result.","expandable":false,"children":[{"name":"success","type":"`boolean`","description":"Whether the authentication was successful.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"authIdentity","type":"[AuthIdentityDTO](/references/auth/interfaces/auth.AuthIdentityDTO)","description":"The authenticated user's details.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the auth identity.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"provider_identities","type":"[ProviderIdentityDTO](/references/auth/interfaces/auth.ProviderIdentityDTO)[]","description":"The list of provider identities linked to the auth identity.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"app_metadata","type":"`Record<string, unknown>`","description":"Holds information related to the actor IDs tied to the auth identity.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"mfaChallenge","type":"[AuthMfaChallengeDTO](/references/auth/types/auth.AuthMfaChallengeDTO)","description":"The multi-factor authentication (MFA) challenge to complete before issuing a token.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The multi-factor authentication (MFA) challenge's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"auth_identity_id","type":"`string`","description":"The ID of the authentication identity being challenged.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"auth_identity","type":"[AuthIdentityDTO](/references/auth/interfaces/auth.AuthIdentityDTO)","description":"The authentication identity being challenged.","optional":true,"defaultValue":"","expandable":true,"children":[]},{"name":"auth_provider","type":"`string` \\| `null`","description":"The authentication provider handling the challenge.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"methods","type":"[AuthMfaChallengeMethod](/references/auth/types/auth.AuthMfaChallengeMethod)[]","description":"Available methods for completing this challenge.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"expires_at","type":"`Date`","description":"When the challenge expires.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"attempts","type":"`number`","description":"Number of verification attempts made.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"max_attempts","type":"`number`","description":"Maximum verification attempts allowed.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"completed_at","type":"`Date` \\| `null`","description":"When the challenge was completed.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"Additional metadata for the challenge.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"error","type":"`string`","description":"If an error occurs during the authentication process,\nwhether within the Auth Module or a third-party provider,\nthe error message is set in this field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location","type":"`string`","description":"The URL to redirect to for further authentication action\nwith a third-party provider. This takes precedence before\nthe `success` field.\n\nSo, after checking that authentication is successful,\nyou should check whether this field is defined and, if so, redirect to the\nspecified location.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]}