Auth Package
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
Auth.AuthContext
) => AuthAbstract
config(authContext:- authContext Configuration object
Config the Auth
instance
new Auth()
.config({ host: 'http://api.beta.cnyes.cool/api/' })
.consumeProviderToken({
type:
})
Auth.ProviderToken
) => Promise<Auth.Credentials>
consumeProviderToken(args:- 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'
})
Promise<Auth.Credentials>
renew() => Invoke this method to update credential context using existing idToken
, and accessToken
.
Returns a promise resolves latest credential context after it's finished.
Auth.Credentials
getCredentials() => Returns credential context stored in storage.