0.0.4 • Published 5 years ago
oauth-ts v0.0.4
@thiagozf/oauth-ts
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();