PKCE తో కస్టమర్ను అధికారం ఇవ్వండి
S256 PKCEతో ShareAI authorization-code ఫ్లోను అమలు చేయండి, stateను ధృవీకరించండి మరియు కోడ్ను మీ అప్లికేషన్ బ్యాకెండ్లో మార్పిడి చేయండి.
ఈ పేజీలో
ఈ ఫ్లో ఒక కస్టమర్ ఖాతాను మీ అప్లికేషన్కు కనెక్ట్ చేస్తుంది. కస్టమర్ సైన్ ఇన్ చేస్తారు, వ్యక్తిగత లేదా సంస్థ ఖాతాను ఎంచుకుంటారు మరియు అభ్యర్థించిన అనుమతులను ఆమోదిస్తారు. మీ బ్యాకెండ్ తరువాత తాత్కాలిక కోడ్ను టోకెన్లకు మార్పిడి చేస్తుంది.
మీరు ప్రారంభించడానికి ముందు#
పూర్తి అప్లికేషన్ రిజిస్ట్రేషన్. మీరు ఖచ్చితంగా రిజిస్టర్ చేసిన callback, సర్వర్-హెల్డ్ క్లయింట్ క్రెడెన్షియల్స్ మరియు బ్రౌజర్ authorizationను పూర్తి చేసే సర్వర్-సైడ్ సెషన్ అవసరం.
1. authorization అభ్యర్థనను సృష్టించండి#
https://auth.shareai.now/oauth/authorizeకస్టమర్ను అప్లికేషన్ను authorization చేయమని అడగండి.
- బేస్ URL
https://auth.shareai.now- authentication
- బ్రౌజర్ రీడైరెక్ట్; రిజిస్టర్ చేసిన అప్లికేషన్
ప్రతి ప్రయత్నానికి కొత్త verifier, state మరియు nonceను ఉత్పత్తి చేయండి. వాటిని ప్రారంభించిన యూజర్ యొక్క సర్వర్-సైడ్ సెషన్లో నిల్వ చేయండి. SHA-256 ఛాలెంజ్ను పంపండి, verifierను కాదు, బ్రౌజర్ రీడైరెక్ట్లో. మీ అప్లికేషన్కు అవసరమైన scopes మాత్రమే అభ్యర్థించండి.
Python
import base64
import hashlib
import secrets
import urllib.parse
verifier = secrets.token_urlsafe(48)
challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode()
state = secrets.token_urlsafe(32)
nonce = secrets.token_urlsafe(32)
# Store verifier, state and nonce in the user's server-side session.
params = {
"response_type": "code",
"client_id": "YOUR_CLIENT_ID",
"redirect_uri": "https://app.example.com/auth/shareai/callback",
"scope": "openid profile surcharge",
"state": state,
"nonce": nonce,
"code_challenge": challenge,
"code_challenge_method": "S256",
}
print("https://auth.shareai.now/oauth/authorize?" + urllib.parse.urlencode(params))
TypeScript
import { randomBytes, createHash } from "node:crypto";
const verifier = randomBytes(48).toString("base64url");
const state = randomBytes(32).toString("base64url");
const nonce = randomBytes(32).toString("base64url");
const challenge = createHash("sha256").update(verifier).digest("base64url");
// Save verifier, state and nonce in the initiating server-side session.
const params = new URLSearchParams({ response_type: "code", client_id: "YOUR_CLIENT_ID",
redirect_uri: "https://app.example.com/auth/shareai/callback",
scope: "openid profile surcharge", state, nonce,
code_challenge: challenge, code_challenge_method: "S256" });
const authorizationUrl = `https://auth.shareai.now/oauth/authorize?${params}`;
// Redirect the browser to authorizationUrl.
2. callbackను ధృవీకరించండి#
authorization తిరస్కరించబడితే, OAuth errorను సాధారణ రద్దుగా నిర్వహించండి. లేకపోతే తిరిగి వచ్చిన state విలువను సేవ్ చేసిన విలువతో పోల్చి కోడ్ను ఉపయోగించే ముందు. state లేకపోవడం లేదా సరిపోలని stateను తిరస్కరించండి. సేవ్ చేసిన stateను ఒకసారి మాత్రమే వినియోగించండి; మరో బ్రౌజర్ సెషన్ ద్వారా సమర్పించిన callback URLsను ఆమోదించవద్దు.
3. కోడ్ను మార్పిడి చేయండి#
https://auth.shareai.now/oauth/tokenఒకసారి ఉపయోగించే కోడ్ మరియు సరిపోలే PKCE verifierను మార్పిడి చేయండి.
- బేస్ URL
https://auth.shareai.now- authentication
- గోప్యమైన క్లయింట్ authentication
cURL
curl --fail-with-body "https://auth.shareai.now/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "client_id=$SHAREAI_CLIENT_ID" \
--data-urlencode "client_secret=$SHAREAI_CLIENT_SECRET" \
--data-urlencode "code=$AUTHORIZATION_CODE" \
--data-urlencode "redirect_uri=https://app.example.com/auth/shareai/callback" \
--data-urlencode "code_verifier=$PKCE_VERIFIER"
క్లయింట్ కోసం కాన్ఫిగర్ చేసిన క్లయింట్ authentication పద్ధతిని ఉపయోగించండి. ఉదాహరణ ఫారమ్-ఆధారిత క్లయింట్ authenticationను ఉపయోగిస్తుంది. అదే కోడ్ను రెండుసార్లు పంపవద్దు; వినియోగించిన లేదా గడువు ముగిసిన కోడ్ తర్వాత authorizationను మళ్లీ ప్రారంభించండి.
4. ఫలితాన్ని నిల్వ చేసి మీ యాప్ సెషన్ను స్థాపించండి#
access మరియు refresh టోకెన్లను మీ బ్యాకెండ్లో నిల్వ చేయండి. తిరిగి వచ్చిన expires_in టోకెన్ శాశ్వతమని అనుమానించకుండా ఉపయోగించండి. మీరు ID టోకెన్ను ఉపయోగిస్తే, దాని సంతకం, issuer యొక్క JWKS, ఆశించిన issuer, క్లయింట్ ఆడియన్స్, గడువు మరియు మీ అసలు nonceతో ధృవీకరించండి.
లైఫ్సైకిల్ను కొనసాగించండి#
Refresh మరియు rotation · Scopes మరియు ఖాతా గుర్తింపు · OAuth చాట్ అభ్యర్థనలు
చివరిసారిగా నవీకరించబడింది సెప్టెంబర్ 15, 2026