SalteAuth
Authentication Controller
Constructor Summary
Public Constructor | ||
public |
constructor(config: Config) Sets up Salte Auth |
Member Summary
Public Members | ||
public |
mixin: * A mixin built for Web Components |
|
public |
The user profile for salte auth |
Method Summary
Public Methods | ||
public |
Registers a timeout that will automatically refresh the id token |
|
public |
loginWithIframe(config: Boolean | LoginConfig): Promise<Object> Authenticates using the iframe-based OAuth flow. |
|
public |
Authenticates using the tab-based OAuth flow. |
|
public |
Authenticates using the popup-based OAuth flow. |
|
public |
loginWithRedirect(redirectUrl: String): Promise Authenticates using the redirect-based OAuth flow. |
|
public |
Unauthenticates using the iframe-based OAuth flow. |
|
public |
Unauthenticates using the tab-based OAuth flow. |
|
public |
Unauthenticates using the popup-based OAuth flow. |
|
public |
Logs the user out of their configured identity provider. |
|
public |
Deregister a callback previously registered. |
|
public |
Listens for an event to be invoked. |
|
public |
Refreshes the users tokens and renews their session. |
|
public |
Authenticates, requests the access token, and returns it if necessary. |
Public Constructors
Public Members
public mixin: * source
A mixin built for Web Components
Example:
class MyElement extends auth.mixin(HTMLElement) {
constructor() {
super();
console.log(this.auth); // This is the same as auth
console.log(this.user); // This is the same as auth.profile.userInfo.
console.log(this.authenticated); // This is the same as auth.profile.idTokenExpired.
}
}
Public Methods
public loginWithIframe(config: Boolean | LoginConfig): Promise<Object> source
Authenticates using the iframe-based OAuth flow.
Params:
Name | Type | Attribute | Description |
config | Boolean | LoginConfig | Whether this request is intended to refresh the token. |
Example:
auth.loginWithIframe().then((user) => {
console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public loginWithNewTab(): Promise<Object> source
Authenticates using the tab-based OAuth flow.
Example:
auth.loginWithNewTab().then((user) => {
console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public loginWithPopup(): Promise<Object> source
Authenticates using the popup-based OAuth flow.
Example:
auth.loginWithPopup().then((user) => {
console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public loginWithRedirect(redirectUrl: String): Promise source
Authenticates using the redirect-based OAuth flow.
Params:
Name | Type | Attribute | Description |
redirectUrl | String | override for the redirect url, by default this will try to redirect the user back where they started. |
Example:
auth.loginWithRedirect(); // Don't bother with utilizing the promise here, it never resolves.
public logoutWithIframe(): Promise source
Unauthenticates using the iframe-based OAuth flow.
Example:
auth.logoutWithIframe().then(() => {
console.log('success!');
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public logoutWithNewTab(): Promise source
Unauthenticates using the tab-based OAuth flow.
Example:
auth.logoutWithNewTab().then(() => {
console.log('success!');
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public logoutWithPopup(): Promise source
Unauthenticates using the popup-based OAuth flow.
Example:
auth.logoutWithPopup().then(() => {
console.log('success!');
}).catch((error) => {
console.error('Whoops something went wrong!', error);
});
public logoutWithRedirect() source
Logs the user out of their configured identity provider.
Example:
auth.logoutWithRedirect();
public off(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function) source
Deregister a callback previously registered.
Params:
Name | Type | Attribute | Description |
eventType | 'login' | 'logout' | 'refresh' | 'expired' | the event to deregister. |
|
callback | Function | A callback that fires when the specified event occurs. |
Example:
const someFunction = function() {};
auth.on('login', someFunction);
auth.off('login', someFunction);
public on(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function) source
Listens for an event to be invoked.
Params:
Name | Type | Attribute | Description |
eventType | 'login' | 'logout' | 'refresh' | 'expired' | the event to listen for. |
|
callback | Function | A callback that fires when the specified event occurs. |
Example:
auth.on('login', (error, user) => {
if (error) {
console.log('something bad happened!');
}
console.log(user); // This is the same as auth.profile.userInfo.
});
window.addEventListener('salte-auth-login', (event) => {
if (event.detail.error) {
console.log('something bad happened!');
}
console.log(event.detail.data); // This is the same as auth.profile.userInfo.
});