npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tryauth/tryauth-client-ts

v1.0.23

Published

TypeScript library for OAuth2 Authentication

Downloads

102

Readme

tryauth-client-ts

NPM version

Index

Install

From npm:

npm install @tryauth/tryauth-client-ts

After installing the tryauth-client-ts module using npm, you'll need to import it using:

import TryAuth from '@tryauth/tryauth-client-ts';

Implicit Flow

Provides support for implicit authentication flow.

Initialize

The Authorize will redirect to the Issuer Endpoint than the user can login.

const tryAuth: TryAuth = new TryAuth();
tryAuth.Authorize({
    ClientId: '<contact us to get a trial ClientId>',
    IssuerEndpoint: '<contact us to get a trial Issuer Endpoint>',
    ResponseType: 'token id_token', // return id_token and access_token in querystring
    Scopes: 'openid email'
    // RedirectUri: ''  it's not required, window.location it's the default value
});

Parameters

| Option|Type|Description| | :---------------------------- | ----------------- | ---------- | | ClientId| string (required) | The Client ID found on your Application settings page. | IssuerEndpoint| string (required) | Your TryAuth account domain such as 'example.tryauth.com' or 'example.tryauth.com'. | ResponseType| string (required) | Response type for all authentication requests. Only supports token id_token. | Scopes| string (required) | The default scopes used for all authorization requests. | RedirectUri | string | The URL where TryAuth will call back to with the result of a successful or failed authentication.

Check

Allows to acquire a new token and/or access token for a user who has already authenticated against TryAuth for your domain. If the user is not authenticated, you will receive an error.

const tryAuth: TryAuth = new TryAuth();
const tryAuthAuthorizationResponse = await tryAuth.CheckAuthorize();

console.log('AccessToken=' + tryAuthAuthorizationResponse.AccessToken);
console.log('IdToken=' + tryAuthAuthorizationResponse.IdToken);
console.log('ExpiresAt=' + tryAuthAuthorizationResponse.ExpiresAt);
console.log('Email=' + tryAuthAuthorizationResponse.Email);
console.log('Error=' + tryAuthAuthorizationResponse.Error);

Authorization Code Flow

Provides support for authorization_code authentication flow with PKCE (Proof Key for Code Exchange).

Initialize

The GetAuthorizationCode function will redirect to the Issuer Endpoint than the user can login. After login the response callback URL will store the code in the browser's local storage.

const tryAuth: TryAuth = new TryAuth();
tryAuth.GetAuthorizationCode({
    ClientId: '<contact us to get a trial ClientId>',
    IssuerEndpoint: '<contact us to get a trial Issuer Endpoint>',
    ResponseType: 'code',
    Scopes: 'openid email profile offline_access',
    // RedirectUri: ''  it's not required, window.location it's the default value
});

Parameters

| Option|Type|Description| | :---------------------------- | ----------------- | ---------- | | ClientId| string (required) | The Client ID found on your Application settings page. | IssuerEndpoint| string (required) | Your TryAuth account domain such as 'example.tryauth.com' or 'example.tryauth.com'. | ResponseType| string (required) | Response type for all authentication requests. Only supports code. | Scopes| string (required) | The default scopes used for all authorization requests. Enable refresh token adding offline_access scope. | RedirectUri | string | The URL where TryAuth will call back to with the result of a successful or failed authentication.

Get Access Token, Id Token and optional Refresh Token code

After you login and the code already is stored in the browser's local storage you can get the access_token, id_token, refresh_token (optional, dependes on the offline_access scope) using the GetSilentAuthorizationCodeToken function.

The code only can be used one time.

const tryAuth: TryAuth = new TryAuth();
const tryAuthAuthorizationCodeTokenResponse = tryAuth.GetSilentAuthorizationCodeToken({
    ClientId: '<contact us to get a trial ClientId>',
    ClientSecret: '<contact us to get a trial ClientSecret>',
    IssuerEndpoint: '<contact us to get a trial Issuer Endpoint>',
    ResponseType: 'code'
});

Parameters

| Option|Type|Description| | :---------------------------- | ----------------- | ---------- | | ClientId| string (required) | The Client ID found on your Application settings page. | ClientSecret| string (required) | The Client Secret found on your Application settings page. | IssuerEndpoint| string (required) | Your TryAuth account domain such as 'example.tryauth.com' or 'example.tryauth.com'. | ResponseType| string (required) | Response type for all authentication requests. Only supports code.

Return

The tryAuthAuthorizationCodeTokenResponse object contains some properties like:

| Property| | :---------------------------- | |AccessToken| |IdToken| |RefreshToken| |TokenType| |Error|

Renew the Access Token using Refresh Token

If you choose to receive the Refresh Token using the offline_access scope, you can renew your Access Token using the GetAuthorizationCodeRefreshToken function.

const tryAuth: TryAuth = new TryAuth();
const tryAuthAuthorizationCodeTokenResponse = tryAuth.GetAuthorizationCodeRefreshToken({
    ClientId: '<contact us to get a trial ClientId>',
    ClientSecret: '<contact us to get a trial ClientSecret>',
    IssuerEndpoint: '<contact us to get a trial Issuer Endpoint>',
    RefreshToken: '<the refresh token code you receive in the function above>'
});

Parameters

| Option|Type|Description| | :---------------------------- | ----------------- | ---------- | | ClientId| string (required) | The Client ID found on your Application settings page. | ClientSecret| string (required) | The Client Secret found on your Application settings page. | IssuerEndpoint| string (required) | Your TryAuth account domain such as 'example.tryauth.com' or 'example.tryauth.com'. | RefreshToken| string (required) | The refresh token code you receive in the function above.

Return

The tryAuthAuthorizationCodeTokenResponse object is the same of GetSilentAuthorizationCodeToken function above.

Logout

For logout use the LogoutEndSessionAuthorizationCode function.

const tryAuth: TryAuth = new TryAuth();
tryAuth.LogoutEndSessionAuthorizationCode({
    ResponseType: 'code',
    IssuerEndpoint: '<contact us to get a trial Issuer Endpoint>',
    RedirectUri: '<after logout the url return>',
    IdToken: '<id_token>',
    State: 'the state in url'
});

Parameters

| Option|Type|Description| | :---------------------------- | ----------------- | ---------- | | ResponseType| string (required) | code | IssuerEndpoint| string (required) | Your TryAuth account domain such as 'example.tryauth.com' or 'example.tryauth.com'. | RedirectUri| string (required) | After logout TryAuth will redirect to this URL. | IdToken| string (required) | The id_token you receive when you get the token. | State| string (required) | After log in the state will be in the URL.