
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@curity/token-handler-js-assistant
Advanced tools
A helper library to help SPAs interact with the OAuth Agent in the Token Handler pattern.
Add to your project using npm
npm install @curity/token-handler-js-assistant
Import the Assistant into your project and initialize it using Configuration
object.
import {OAuthAgentClient} from "@curity/token-handler-js-assistant";
const client = new OAuthAgentClient({oauthAgentBaseUrl: 'https://api.example.com/oauthagent/example'})
The Configuration
object contains the following options:
oauthAgentBaseUrl
- a URL with path to the token handler application created in the Curity Identity Server (this URL ends with a token handler application ID
as defined in the Curity Identity Server configuration).const response = await this.oauthAgentClient.startLogin({
extraAuthorizationParameters: {
scope: "openid profile",
login_hint: "username",
ui_locales: "en"
}
})
location.href = response.authorizationUrl
const url = new URL(location.href)
const response = await client.endLogin({ searchParams: url.searchParams })
if (response.isLoggedIn) {
// use id token claims to get username, e.g. response.idTokenClaims?.sub
}
Note: The endLogin
function should only be called with authorization response parameters (when the authorization
server redirected user to the SPA after a successful user login). It's recommended to call onPageLoad()
instead
on every load of the SPA. This function makes a decision based the query string and either calls endLogin()
or session()
.
const sessionResponse = await client.onPageLoad(location.href)
if (sessionResponse.isLoggedIn) {
// user is logged in
} else {
const response = await client.startLogin()
// redirect the user to the authorization server
location.href = response.authorizationUrl
}
await client.refresh()
const sessionResponse = await client.session()
// use session data
if (session.isLoggedIn === true) {
session.idTokenClaims?.sub
}
const logoutResponse = await client.logout()
if (logoutResponse.logoutUrl) {
// redirect user to the single logout url
location.href = logoutResponse.logoutUrl;
}
FAQs
Curity Token Handler JavaScript helper library
We found that @curity/token-handler-js-assistant demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.