Auth package manages application credentials by using Network and Storage.
[TOC]
Import the package
The Auth package exports a class constructor which manages credential to a single tenant.
import Auth from '@anue-fe-sdk/packages/Auth'
new Auth().config({
host: 'http://api.beta.cnyes.cool/api/'
})
Class Methods
config(authContext:Auth.AuthContext) => AuthAbstract
- authContext Configuration object
Config the Auth instance
new Auth()
.config({ host: 'http://api.beta.cnyes.cool/api/' })
.consumeProviderToken({
type:
})
consumeProviderToken(args:Auth.ProviderToken) => Promise<Auth.Credentials>
- args An object containing type of the provider and complete token information
Authenticate by given provider token and type,
when args.type is google the field idToken is required.
const googleCredentials = await getGoogleCredentials()
const auth = new Auth()
.config({ host: 'http://api.beta.cnyes.cool/api/' })
await auth.consumeProviderToken({
type: 'google',
idToken: googleCredential.id_token,
accessToken: googleCredential.access_token,
channel: 'driver'
})
renew() => Promise<Auth.Credentials>
Invoke this method to update credential context using existing idToken, and accessToken.
Returns a promise resolves latest credential context after it's finished.
getCredentials() => Auth.Credentials
Returns credential context stored in storage.