Start OAuth Authorization - Stytch Docs
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
C#
// POST /v1/b2b/idp/oauth/authorize/start
const stytch = require('stytch');
const client = new stytch.B2BClient({
project_id: '${projectId}',
secret: '${secret}',
});
const params = {
client_id: "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
redirect_uri: "https://app.example/oauth/callback",
response_type: "code",
scopes: ["openid"],
};
client.IDP.OAuth.AuthorizeStart(params)
.then(resp => { console.log(resp) })
.catch(err => { console.log(err) });
Go
// POST /v1/b2b/idp/oauth/authorize/start
package main
import (
"context"
"log"
"github.com/stytchauth/stytch-go/v18/stytch/b2b/b2bstytchapi"
"github.com/stytchauth/stytch-go/v18/stytch/b2b/idp/oauth"
)
func main() {
client, err := b2bstytchapi.NewClient(
"${projectId}",
"${secret}",
)
if err != nil {
log.Fatalf("error instantiating client: %v", err)
}
params := &oauth.AuthorizeStartParams{
ClientID: "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
RedirectURI: "https://app.example/oauth/callback",
ResponseType: "code",
Scopes: []string{"openid"},
}
resp, err := client.IDP.OAuth.AuthorizeStart(context.Background(), params)
if err != nil {
log.Fatalf("error in method call: %v", err)
}
log.Println(resp)
}
Java
// POST /v1/b2b/idp/oauth/authorize/start
package com.example;
import com.stytch.java.b2b.models.idpoauth.AuthorizeStartRequest;
import com.stytch.java.b2b.StytchB2BClient;
import com.stytch.java.common.StytchResult;
public class Main {
public static void main(String[] args) {
StytchB2BClient.configure("${projectId}", "${secret}");
AuthorizeStartRequest params = new AuthorizeStartRequest();
params.setClientId("connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888");
params.setRedirectUri("https://app.example/oauth/callback");
params.setResponseType("code");
params.setScopes(new String("openid"));
Object result = StytchB2BClient.getIDP().getOAuth().authorizeStart(params);
if (result instanceof StytchResult.Success) {
System.out.println(((StytchResult.Success) result).getValue());
} else {
System.out.println(((StytchResult.Error) result).getException());
}
}
}
Kotlin
// POST /v1/b2b/idp/oauth/authorize/start
package com.example
import com.stytch.java.b2b.StytchB2BClient
import com.stytch.java.b2b.models.idpoauth.AuthorizeStartRequest
fun main() {
StytchB2BClient.configure(
projectId = "${projectId}",
secret = "${secret}",
)
when (
val result =
StytchB2BClient.idp.oauth.authorizeStart(
AuthorizeStartRequest(
clientId = "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
redirectUri = "https://app.example/oauth/callback",
responseType = "code",
scopes = arrayOf("openid"),
),
)
) {
is StytchResult.Success -> println(result.value)
is StytchResult.Error -> println(result.exception)
}
}
Node.js
// POST /v1/b2b/idp/oauth/authorize/start
const stytch = require('stytch');
const client = new stytch.B2BClient({
project_id: '${projectId}',
secret: '${secret}',
});
client.idp.oauth.authorizeStart(params)
.then(resp => { console.log(resp) })
.catch(err => { console.log(err) });
PHP
$response = $client->idp->oauth->authorize_start([
'client_id' => 'connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888',
'redirect_uri' => 'https://app.example/oauth/callback',
'response_type' => 'code',
'scopes' => ['openid'],
]);
Python
# POST /v1/b2b/idp/oauth/authorize/start
from stytch import B2BClient
client = B2BClient(
project_id="${projectId}",
secret="${secret}",
)
resp = client.idp.oauth.authorize_start(
client_id="connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
redirect_uri="https://app.example/oauth/callback",
response_type="code",
scopes=["openid"],
)
print(resp)
Ruby
# frozen_string_literal: true
# POST /v1/b2b/idp/oauth/authorize/start
require 'stytch'
client = StytchB2B::Client.new(
project_id: "${projectId}",
secret: "${secret}"
)
resp = client.idp.oauth.authorize_start(
client_id: "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
redirect_uri: "https://app.example/oauth/callback",
response_type: "code",
scopes: ['openid']
)
puts resp
Rust
// POST /v1/b2b/idp/oauth/authorize/start
use stytch::b2b::client::Client;
use stytch::b2b::idp_oauth::AuthorizeStartRequest;
fn main() {
let client = Client::new("${projectId}", "${secret}").unwrap();
let resp = client.idp.oauth.authorize_start(
AuthorizeStartRequest{
client_id: "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
redirect_uri: "https://app.example/oauth/callback",
response_type: "code",
scopes: vec!["openid"],
..Default::default()
}
).await;
println!("The response is {:?}", resp);
}
Curl
// POST /v1/b2b/idp/oauth/authorize/start
curl --request POST \
--url https://test.stytch.com/v1/b2b/idp/oauth/authorize/start \
-u '${projectId}:${secret}' \
-H 'Content-Type: application/json' \
-d '{
"client_id": "connected-app-test-d731954d-dab3-4a2b-bdee-07f3ad1be888",
"redirect_uri": "https://app.example/oauth/callback",
"response_type": "code",
"scopes": ["openid"]
}'
Response Codes
- 200
- 401
- 429
- 500
API Endpoint Description
Initiates a request for authorization of a Connected App to access a Members’s account. Call this endpoint using the query parameters from an OAuth Authorization request. This endpoint validates various fields (scope, client_id, redirect_uri, prompt, etc…) are correct and returns relevant information for rendering an OAuth Consent Screen.
This endpoint returns:
- A public representation of the Connected App requesting authorization
- Whether explicit user consent must be granted before proceeding with the authorization
- A list of scopes the user has the ability to grant the Connected App
Use this response to prompt the user for consent (if necessary) before calling the Submit OAuth Authorization endpoint.
Authorizations
Authorization header required.
Body Parameters
- client_id: The ID of the Connected App client.
- redirect_uri: The callback URI used to redirect the user after authentication.
- response_type: The OAuth 2.0 response type ('code').
- scopes: An array of requested scopes.
- member_id, session_token, or session_jwt required for identification.
Response Fields
- request_id: UUID of the API call.
- member: The Member object.
- organization: The Organization object.
- client: The Client object.
- consent_required: Whether explicit consent is required.
- scope_results: Details about requested scopes.
- status_code: HTTP status code.