@salesforce/b2c-tooling-sdk / auth / PkceOAuthStrategy
Class: PkceOAuthStrategy
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:421
OAuth 2.0 Authorization Code Flow with PKCE.
Used for public clients (no client secret). Replaces the legacy implicit flow, which is deprecated for public clients per OAuth 2.1.
Flow:
- Generate PKCE verifier + S256 challenge.
- Open browser to
/dwsso/oauth2/authorize?response_type=code&code_challenge=.... - Capture redirect with
?code=...on a localhost listener. - POST
grant_type=authorization_code+code_verifierto/dwsso/oauth2/access_token.
Tokens may include a refresh_token (depends on client registration in Account Manager).
Implements
Constructors
Constructor
new PkceOAuthStrategy(
config):PkceOAuthStrategy
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:434
Parameters
config
Returns
PkceOAuthStrategy
Properties
authMethod
readonlyauthMethod:"user"
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:422
Methods
fetch()
fetch(
url,init):Promise<Response>
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:499
Performs a fetch request with authentication. Implementations MUST handle header injection and 401 retries (token refresh) internally.
Parameters
url
string
init
FetchInit = {}
Returns
Promise<Response>
Implementation of
getAuthorizationHeader()
getAuthorizationHeader():
Promise<string>
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:528
Optional: Helper for legacy clients (like a strict WebDAV lib) that need the raw header.
Returns
Promise<string>
Implementation of
AuthStrategy.getAuthorizationHeader
getCachedTokenResponse()
getCachedTokenResponse():
AccessTokenResponse|undefined
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:553
The cached access token, if it is still usable, without refreshing or signing in. Returns undefined when a network call or sign-in would be needed.
Returns
AccessTokenResponse | undefined
getJWT()
getJWT():
Promise<DecodedJWT>
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:533
Returns
Promise<DecodedJWT>
getTokenResponse()
getTokenResponse():
Promise<AccessTokenResponse>
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:538
Returns
Promise<AccessTokenResponse>
invalidateToken()
invalidateToken():
void
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:616
Optional: Invalidates the cached token, forcing re-authentication on next request. Used by middleware to retry requests after receiving a 401 response.
Returns
void
Implementation of
signIn()
signIn():
Promise<AccessTokenResponse>
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:563
Run the interactive sign-in now, even when interactive is false or a session already exists. Use it from a host's "Sign in" action.
Returns
Promise<AccessTokenResponse>
signOut()
signOut():
void
Defined in: packages/b2c-tooling-sdk/src/auth/oauth-pkce.ts:574
Forget this client's session: the cached access token, the refresh token and the stored session record.
Returns
void