B2B Saas Authentication

/

Frontend SDKs

/

Headless

/

OAuth

/

Start OAuth Flow

Start OAuth flow

The oauth.$provider.start() methods start OAuth flows by redirecting the browser to one of Stytch's OAuth Start endpoints. One of organization_id or slug is required to specify which organization the user is trying to access. If the organization that the user is trying to access is not yet known, use the oauth.$provider.discovery.start() method instead.

The method will also generate a PKCE code_verifier and store it in local storage on the device (See the PKCE OAuth guide for details). If your application is configured to use a custom subdomain with Stytch, it will be used automatically.

  • oauth.google.start()
  • oauth.microsoft.start()
  • oauth.hubspot.start()
  • oauth.slack.start()

Method parameters


organization_idstring

slugstring

login_redirect_urlstring

signup_redirect_urlstring

custom_scopesstring

provider_paramsobject
import { useStytchB2BClient } from '@stytch/react/b2b';

export const Login = () => {
  const stytch = useStytchB2BClient();

  const startOAuth = () =>
    stytch.oauth.google.start({
      organization_id: 'organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931',
      login_redirect_url: 'https://example.com/authenticate',
      signup_redirect_url: 'https://example.com/authenticate',
      provider_params: {
        login_hint: 'example_hint@stytch.com',
      },
    });

  return <button onClick={startOAuth}>Log in with Google</button>;
};