Skip to content

A vanilla TypeScript library to support OpenID Connect (OIDC) and OAuth2 protocol on browser-based JavaScript applications

License

Notifications You must be signed in to change notification settings

thiagozf/oauth-ts

Repository files navigation

@thiagozf/oauth-ts

Codecov CircleCI

OAuth 2.0 authentication library

How to use

/* MyOAuthApp.ts */
import { OpenIDProvider, OAuthApplication, resolveProvider } from 'oauth-ts';

const provider: OpenIDProvider = await resolveProvider(
  'https://my.oidc.provider.com'
);

export const oauthApp: OAuthApplication = new OAuthApplication({
  provider,
  clientId: 'my_client_id',
  redirectUri: 'http://localhost:3000/callback',
  silentRedirectUri: 'http://localhost:3000/silent-callback',
  scope: 'read write',
  flow: 'IMPLICIT'
});

/* index.ts */
import { oauthApp } from './MyOAuthApp';

if (!oauthApp.hasActiveSession()) {
  return oauthApp.login();
}

console.log(oauthApp.getUser());

/* callback.ts */
import { oauthApp } from './MyOAuthApp';

oauthApp.handleCallback();

About

A vanilla TypeScript library to support OpenID Connect (OIDC) and OAuth2 protocol on browser-based JavaScript applications

Resources

License

Stars

Watchers

Forks

Packages