କ୍ୱିକଷ୍ଟାର୍ଟ: ଯେକୌଣସି OIDC ଲାଇବ୍ରେରୀ
Usher ଏକ ମାନକ OpenID Connect ପ୍ରୋଭାଇଡର। ଯଦି ଆପଣଙ୍କ ଭାଷାରେ ଏକ ସାର୍ଟିଫାଏଡ OIDC କ୍ଲାଏଣ୍ଟ ଅଛି, ଆପଣଙ୍କ ପାଖରେ ଦରକାରୀ ସବୁକିଛି ପୂର୍ବରୁ ଅଛି: ଏହାକୁ ଆପଣଙ୍କ ଏନଭାଇରନମେଣ୍ଟର ଡିସକଭରି ଡକ୍ୟୁମେଣ୍ଟ ଆଡ଼କୁ ଦେଖାନ୍ତୁ ଏବଂ PKCE ସହ ପ୍ରାଧିକରଣ କୋଡ ଫ୍ଲୋ ବ୍ୟବହାର କରନ୍ତୁ।
ସେଟିଂସ
| ସେଟିଂ | ମୂଲ୍ୟ |
|---|---|
| ଇସୁଅର | https://<handle>.usherid.com |
| ଡିସକଭରି URL | https://<handle>.usherid.com/.well-known/openid-configuration |
| ଫ୍ଲୋ | ପ୍ରାଧିକରଣ କୋଡ (response_type=code) |
| PKCE | ଆବଶ୍ୟକ, code_challenge_method=S256 |
| ସ୍କୋପ | openid profile email offline_access |
| କ୍ଲାଏଣ୍ଟ ପ୍ରମାଣୀକରଣ | token_endpoint_auth_methods_supportedରେ ଯେପରି ତାଲିକାଭୁକ୍ତ |
ଆପଣଙ୍କ ଏନଭାଇରନମେଣ୍ଟର ହ୍ୟାଣ୍ଡଲ Usher Consoleରେ, ଏହାର ଇସୁଅର ପାଖରେ ଅଛି। ଡେଭେଲପମେଣ୍ଟ ଏନଭାଇରନମେଣ୍ଟ ଏକ ଅନିୟମିତ ହ୍ୟାଣ୍ଡଲ ପାଏ, ଯେପରି wise-otter-42; ପ୍ରୋଡକ୍ସନ ଏନଭାଇରନମେଣ୍ଟର ହ୍ୟାଣ୍ଡଲ ଆପଣ ବାଛିଥିବା। ଏକ ପ୍ରୋଡକ୍ସନ ଏନଭାଇରନମେଣ୍ଟ ଏହା ବଦଳରେ ଆପଣଙ୍କ ନିଜ ଡୋମେନରେ ରହିପାରେ, ଯେପରି login.acme.com: ଏକ CNAME ରେକର୍ଡ ଦ୍ୱାରା ଡୋମେନକୁ Usher ଆଡ଼କୁ ଦେଖାଇବା ପରେ, ସେହି ଡୋମେନ ହିଁ ଏହାର ଇସୁଅର।
ଡିସକଭରି ଡକ୍ୟୁମେଣ୍ଟ ପଢ଼ନ୍ତୁ
ଆପଣଙ୍କ କ୍ଲାଏଣ୍ଟର ଦରକାର ହେଉଥିବା ପ୍ରତ୍ୟେକ ଏଣ୍ଡପଏଣ୍ଟ ଓ କୀ ଏଠାରେ ତାଲିକାଭୁକ୍ତ। URL ଆପଣଙ୍କ କୋଡରେ କପି କରିବା ବଦଳରେ ଆପଣଙ୍କ ଲାଇବ୍ରେରୀକୁ ଏହା ପଢ଼ିବାକୁ ଦିଅନ୍ତୁ।
curl -s https://acme.usherid.com/.well-known/openid-configuration | jq{
"issuer": "https://acme.usherid.com",
"authorization_endpoint": "https://acme.usherid.com/api/auth/oauth2/authorize",
"token_endpoint": "https://acme.usherid.com/api/auth/oauth2/token",
"userinfo_endpoint": "https://acme.usherid.com/api/auth/oauth2/userinfo",
"jwks_uri": "https://acme.usherid.com/api/auth/jwks",
"introspection_endpoint": "https://acme.usherid.com/api/auth/oauth2/introspect",
"revocation_endpoint": "https://acme.usherid.com/api/auth/oauth2/revoke",
"end_session_endpoint": "https://acme.usherid.com/api/auth/oauth2/end-session",
"scopes_supported": ["openid", "profile", "email", "offline_access"],
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code", "refresh_token", "client_credentials"],
"code_challenge_methods_supported": ["S256"]
}ଫ୍ଲୋ
ବ୍ୟକ୍ତିଙ୍କୁ ପ୍ରାଧିକରଣ ଏଣ୍ଡପଏଣ୍ଟକୁ ପଠାନ୍ତୁ
ଏକ ଅନିୟମିତ PKCE ଭେରିଫାୟର ତିଆରି କରନ୍ତୁ ଏବଂ ଏକ ଅନିୟମିତ state ସହ ତାହାକୁ ଏପରି ସ୍ଥାନରେ ରଖନ୍ତୁ ଯେଉଁଠି କେବଳ ଏହି ବ୍ରାଉଜରର ସେସନ ପହଞ୍ଚିପାରେ (ଅଳ୍ପ ସମୟର ଏକ httpOnly କୁକି ଭଲ କାମ କରେ)। ତାପରେ response_type=code, ଆପଣଙ୍କ client_id ଓ redirect_uri, ଉପରୋକ୍ତ ସ୍କୋପ, state, ଏବଂ ଆପଣଙ୍କ ଭେରିଫାୟରର S256 code_challenge ସହ ରିଡାଇରେକ୍ଟ କରନ୍ତୁ।
ସେମାନଙ୍କୁ ସାଇନ ଇନ କରିବାକୁ ଦିଅନ୍ତୁ
ଏଠାରୁ ଲବି ଦାୟିତ୍ୱ ନିଏ: ଏହା ଆପଣଙ୍କ ଆପର ନାମ ଦେଖାଏ, ଆପଣଙ୍କ ଏନଭାଇରନମେଣ୍ଟ ଅନୁମତି ଦେଉଥିବା ସାଇନ-ଇନ ପଦ୍ଧତି ଦେଖାଏ, ଏବଂ ପ୍ରଥମ ଥର ସମ୍ମତି ମାଗେ।
କଲବ୍ୟାକ ଯାଞ୍ଚ କରନ୍ତୁ
Usher code ଓ state ସହ ଆପଣଙ୍କ redirect_uriକୁ ରିଡାଇରେକ୍ଟ କରେ। state ଆପଣ ରଖିଥିବା ମୂଲ୍ୟ ସହ ମେଳ ନଖାଇଲେ ଉତ୍ତରଟି ପ୍ରତ୍ୟାଖ୍ୟାନ କରନ୍ତୁ। କୋଡଟି ଗୋଟିଏ ଥର ବ୍ୟବହାର ପାଇଁ ଏବଂ ପାଞ୍ଚ ମିନିଟ ରହେ।
କୋଡକୁ ଟୋକେନ ସହ ବଦଳାନ୍ତୁ
ଆପଣଙ୍କ ସର୍ଭରରୁ, କୋଡ ଓ PKCE ଭେରିଫାୟର ଟୋକେନ ଏଣ୍ଡପଏଣ୍ଟକୁ ପୋଷ୍ଟ କରନ୍ତୁ:
curl -s -X POST https://acme.usherid.com/api/auth/oauth2/token \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code="$CODE" \
-d redirect_uri=https://app.acme.example/callback \
-d code_verifier="$CODE_VERIFIER"ID ଟୋକେନ ଯାଞ୍ଚ କରନ୍ତୁ
jwks_uriର କୀ ବିରୁଦ୍ଧରେ ଏହାର ସିଗ୍ନେଚର ଯାଞ୍ଚ କରନ୍ତୁ, ଏବଂ ଯାଞ୍ଚ କରନ୍ତୁ ଯେ iss ଆପଣଙ୍କ ଇସୁଅର, aud ଆପଣଙ୍କ କ୍ଲାଏଣ୍ଟ ID ଏବଂ exp ଭବିଷ୍ୟତରେ ଅଛି। ଆପଣଙ୍କ ଲାଇବ୍ରେରୀ ଆପଣଙ୍କ ପାଇଁ ଏହା କରେ; ଏହା ବନ୍ଦ ହୋଇନାହିଁ ବୋଲି ନିଶ୍ଚିତ କରନ୍ତୁ।
Node.jsରେ
openid-client ଯାଞ୍ଚ ସମେତ ଉପରୋକ୍ତ ସବୁକିଛି କରେ:
import * as client from 'openid-client'
// discovery: every endpoint and key comes from the issuer
const config = await client.discovery(
new URL('https://acme.usherid.com'),
process.env.USHER_CLIENT_ID!,
process.env.USHER_CLIENT_SECRET!,
)
// 1. send them to the Lobby, with PKCE (S256) and a state to check later
const codeVerifier = client.randomPKCECodeVerifier()
const state = client.randomState()
const url = client.buildAuthorizationUrl(config, {
redirect_uri: 'https://app.acme.example/callback',
scope: 'openid profile email offline_access',
code_challenge: await client.calculatePKCECodeChallenge(codeVerifier),
code_challenge_method: 'S256',
state,
})
// keep codeVerifier and state in a short-lived httpOnly cookie, then redirect to url
// 2. back at /callback: swap the code for tokens
const tokens = await client.authorizationCodeGrant(config, new URL(request.url), {
pkceCodeVerifier: codeVerifier,
expectedState: state,
})
const { sub, email, name } = tokens.claims()!ଅନ୍ୟ ଭାଷାରେ
ଏହି ବହୁଳ ବ୍ୟବହୃତ ଲାଇବ୍ରେରୀଗୁଡ଼ିକ ସମସ୍ତେ ମାନକ OpenID Connect କହନ୍ତି ଏବଂ Usher-ନିର୍ଦ୍ଦିଷ୍ଟ କିଛି ବିନା Usher ସହ କାମ କରନ୍ତି:
| ଭାଷା | ଲାଇବ୍ରେରୀ |
|---|---|
| Python | Authlib |
| Go | golang.org/x/oauth2 ସହ coreos/go-oidc |
| Java | Spring Security OAuth 2.0 Client |
| .NET | Microsoft.AspNetCore.Authentication.OpenIdConnect |
| Ruby | omniauth_openid_connect |
| PHP | jumbojett/openid-connect-php |
ସାଇନ ଇନ ହୋଇ ରହିବା
offline_access ସ୍କୋପ ସହ, ଟୋକେନ ଉତ୍ତରରେ ଏକ ରିଫ୍ରେସ ଟୋକେନ ଥାଏ। ପୁରୁଣା ଆକ୍ସେସ ଟୋକେନର ମିଆଦ ପୂରିଲେ ନୂଆଟିଏ ପାଇବାକୁ grant_type=refresh_token ସହ ଏହା ବ୍ୟବହାର କରନ୍ତୁ। ରିଫ୍ରେସ ଟୋକେନ ବଦଳେ: ପ୍ରତି ବ୍ୟବହାରରେ ଏକ ନୂଆ ଟୋକେନ ଆସେ, ଏବଂ ପୁରୁଣାଟି କାମ କରିବା ବନ୍ଦ କରେ।
ସାଇନ ଆଉଟ
ପ୍ରଥମେ ଆପଣଙ୍କ ନିଜ ସେସନ ସଫା କରନ୍ତୁ, ତାପରେ post_logout_redirect_uri ସହ (ଏବଂ ଥିଲେ id_token_hint ସହ) end_session_endpointକୁ ରିଡାଇରେକ୍ଟ କରନ୍ତୁ, ଯାହାଦ୍ୱାରା ଲବି ମଧ୍ୟ ବ୍ୟକ୍ତିଙ୍କୁ ଭୁଲିଯାଏ।