By default, all redirect URLs are set to
http://localhost:3000/authenticate for Test environments.Structure
slack://auth/callback).
-
Protocol: e.g.
https://orhttp://. -
Domain: e.g.
example.com,www.example.com, andexample.comare considered equivalent. -
Path: This route is where your backend will accept the redirect and authenticate the user (e.g.
/authenticate). -
Public token: For our Passwords product, your
public_tokenis included in the redirect URL to allow our JavaScript SDK, if you use it, to complete the authentication flow. -
Stytch token type: The
stytch_token_typequery parameter indicates which product and authentication flow the user is currently completing. You’ll use this value to call the appropriate Authenticate endpoint. For example, a value ofstytch_token_type=magic_linksindicates that you’ll need to call the Magic Links Authenticate endpoint with the token to complete the authentication flow.
Possible values are in our Consumer API are:magic_links: Used by our Email Magic Links product.oauth: Used by our OAuth product.reset_password: Used by our Passwords product during the reset password flow.login: Used by our Passwords product during the reset flow as the alternative one click login.
-
Token: The token value that you’ll pass to the appropriate Authenticate endpoint, e.g.
token=rM_kw42CWBhsHLF62V75jELMbvJ87njMe3tFVj7Qupu7. - Organization slug: For redirect URLs in our B2B API, the slug parameter indicates which Organization the redirect URL pertains to. This query parameter will only be included in Organization-based authentication flows, and not Discovery flows (where the Organization is not yet known).
-
Query parameters: You may set any arbitrary query parameters and include state data within the redirect URL. See the Query parameters section below, e.g.
?next_route=profile.
Example redirect URLs
Security
For security, a redirect URL must be added in the Dashboard before being used. This prevents bad actors from creating a fake login portal, phishing your users, and redirecting them to a site they control. In the Dashboard, you may set a default redirect URL for each type which allows you to omit setting it as a parameter when making the associated API call. Redirect URLs are not shared across project environments, and must be added to each individually.Testing
To make testing and development easier, you may use local, non-HTTPS, addresses (e.g.http://localhost:3000) in Test environments. All Live redirect URLs must use HTTPS.
In Test environments, you may also use * to specify a wildcard for the domain. For example, https://\*.stytch.com. Query parameters cannot contain wildcards and must be an exact match.
This can be helpful in generating preview environments (e.g. https://myapp-\*.vercel.app).
Query parameters
Redirect URLs can optionally include query parameters. Query parameters can be useful as an alternative way to persist state outside of browser cookies and local storage during authentication. URLs must be an exact match. If you have an optional query parameteroptional_param, create two redirect URLs: https://www.example.com and https://www.example.com?optional_param={}.
User app state example
An e-commerce app may want to persist a user’s shopping cart and other app state in their URL so they can serve the user a tailored checkout experience post-login, e.g.https://www.example.com/signup?cart_id=123&promo_banner=true.
Query parameters can be defined as part of the redirect URL in the Dashboard using the pattern param_name={}. In the example above, the developer would need to set the following redirect URL in the Dashboard, https://www.example.com/signup?cart_id={}&promo_banner={}.
Returning to current page example
Another common use case for query parameters is storing the current route location of a user before they authenticate. That way, after a user logs in, your application can parse this value from the query parameters, and redirect the user to the same page that they were on before authenticating.- Add a redirect URL like
https://www.example.com/authenticate?next\_route={}in the Dashboard. - When starting an authentication flow that features a redirect, grab the current page path, and pass the full redirect URL as a parameter in your call to Stytch (e.g.
https://www.example.com/authenticate?next\_route=/profile/details/) - After redirecting to
https://www.example.com/authenticateand successfully authenticating, finally redirect your user to the path stored innext_route(e.g.https://www.example.com/profile/details/).
Native redirect URLs
Native redirect URLs for desktop and mobile applications are also supported, for exampleslack://auth/callback.
If you are using Email Magic Links or Passwords along with native redirect URLs you may need to make additional configuration changes.