Provide OpenID Connect (OIDC) and OAuth2 protocol support for JavaScript/Typescript client applications.
Run yarn run build
For development (watch mode) Run
yarn run watch
.
Import the module
import { IdentityAuth } from "@wso2/identity-oidc-js";`
/**
* Minimal required configuration sample to initialize the client
*/
const authConfig = {
loginCallbackURL: "https://localhost:9000/myapp/home",
logoutCallbackURL: "https://localhost:9000/myapp/login",
clientHost: "https://localhost:9000",
clientID: "KwrHtf9iJdr6ewr0A9IYKIErR0rt",
serverOrigin: "https://localhost:9443"
};
/**
* Initialize authClient
*/
const authClient = new IdentityAuth(authConfig);
Required options
Config | Type | Default | Description |
---|---|---|---|
loginCallbackURL |
string | - | Where to redirect upon successful authentication. (Note:- This should be configured in WSO2 Identity Server) E.g. https://mydomain.com/myapp/home |
logoutCallbackURL |
string | - | Where to redirect after logout. (Note:- This should be configured in WSO2 Identity Server) E.g. https://mydomain.com/myapp/login |
clientHost |
string | - | Application origin address with tenant path if applicable . E.g. https://mydomain.com or https://mydomain.com/t/exmaple.com |
clientID |
string | - | OIDC Application clientID generated in WSO2 Identity Server |
serverOrigin |
string | - | WSO2 Identity Server address. E.g. https://is.mydomain.com |
Optional configurations
Config | Type | Default | Description |
---|---|---|---|
autherizationType |
string | "authorization_code" | |
clientSecret |
string | - | OIDC Application clientSecret generated in WSO2 Identity Server |
consentDenied |
boolean | false | |
enablePKCE |
boolean | true | |
prompt |
string | "" | "none", "login", "consent" |
responseMode |
string | "query" | "query" or "form_post" |
scope |
array | [ "" ] | |
tenant |
string | "carbon.super" | Tenant name. (Note:- Leave it blank for super tenant) E.g. example.com |
tenantPath |
string | "" | Tenant Path. (Note:- Leave it blank for super tenant) E.g. /t/example.com |
authClient.signIn(() => {
// Callback method trigger before signin redirection
})
.then((response) => {
// Response with basic user details upon logged in
})
.catch((error) => {
// Handle erorr
});
authClient.signOut(() => {
// Callback method trigger before signout redirection
})
.catch((error) => {
// Handle erorr
});
Licenses this source under the Apache License, Version 2.0 (LICENSE), You may not use this file except in compliance with the License.