AuthContainer
Direct Subclass:
Auth container
Provides User authentications and user roles API.
Constructor Summary
| Public Constructor | ||
| public |
|
|
Member Summary
| Public Members | ||
| public get |
accessToken: String Current access token |
|
| public get |
Currently logged-in user |
|
Method Summary
| Public Methods | ||
| public |
async adminDisableUser(user: Record | String, message: String, expiry: Date): Promise<String> Disable user account of a user. |
|
| public |
async adminEnableUser(user: Record | String): Promise<String> Enable user account of a user. |
|
| public |
async adminResetPassword(user: Record | String, newPassword: String): Promise<String> Reset user password, require master key. |
|
| public |
async assignUserRole(users: Record[] | String[], roles: Role[] | String[]): Promise<String[]> Assigns roles to users. |
|
| public |
async authHandler(): Promise Auth flow handler script |
|
| public |
async changePassword(oldPassword: String, newPassword: String, invalidate: Boolean): Promise<Record> Changes the password of the current user. |
|
| public |
async fetchUserRole(users: Record[] | String[]): Promise<Object> Gets roles of users from server. |
|
| public |
async forgotPassword(email: String): Promise Send a forgot password email to the email address. |
|
| public |
getLinkRedirectResult(): Promise Get redirect link result, return user from redirect based login flow if link success, promise resolve with result { result: 'OK' }. |
|
| public |
getLoginRedirectResult(): Promise Get redirect login result, return user from redirect based login flow if login success, promise resolve with logged in user. |
|
| public |
async getOAuthProviderProfiles(): Promise Get current user's provider profiles, can use for determine user logged in provider |
|
| public |
async iframeHandler(): Promise Iframe handler script. |
|
| public |
async linkOAuthProviderWithAccessToken(provider: String, accessToken: String): Promise Link oauth provider with access token |
|
| public |
async linkOAuthProviderWithPopup(provider: String, options: Object): Promise Link oauth provider with popup window |
|
| public |
linkOAuthProviderWithRedirect(provider: String, options: Object): Promise Link oauth provider with redirect |
|
| public |
Logs in to an existing user account with the specified auth data and password. |
|
| public |
async loginOAuthProviderWithAccessToken(provider: String, accessToken: String): Promise Login oauth provider with access token |
|
| public |
async loginOAuthProviderWithPopup(provider: String, options: Object): Promise Login oauth provider with popup window |
|
| public |
loginOAuthProviderWithRedirect(provider: String, options: Object): Promise Login oauth provider with redirect |
|
| public |
async loginWithCustomToken(token: String): Promise Login with custom token. |
|
| public |
async loginWithEmail(email: String, password: String): Promise<Record> Logs in to an existing user account with the specified email and password. |
|
| public |
async loginWithProvider(provider: String, authData: Object): Promise<Record> Logs in to an existing user account with custom auth provider. |
|
| public |
async loginWithUsername(username: String, password: String): Promise<Record> Logs in to an existing user account with the specified username and password. |
|
| public |
async logout(): Promise Logs out the current user of this container. |
|
| public |
onUserChanged(listener: function()): EventHandle Registers listener which user record changed. |
|
| public |
async requestVerification(recordKey: String): Promise Request to verify user data. |
|
| public |
async resetPassword(userID: String, code: String, expireAt: Number, newPassword: String): Promise Reset password with a code generated by the server. |
|
| public |
async revokeUserRole(users: Record[] | String[], roles: Role[] | String[]): Promise<String[]> Revokes roles from users. |
|
| public |
async setAdminRole(roles: Role[]): Promise<String[]> Defines roles to have admin right. |
|
| public |
async setDefaultRole(roles: Role[]): Promise<String[]> Sets default roles for new registered users. |
|
| public |
Creates a user account with the specified auth data, password and user record data. |
|
| public |
async signupAnonymously(): Promise<Record> Creates an anonymous user account and log in as the created user. |
|
| public |
async signupWithEmail(email: String, password: String, data: Object): Promise<Record> Creates a user account with the specified email, password and user record data. |
|
| public |
async signupWithUsername(username: String, password: String, data: Object): Promise<Record> Creates a user account with the specified username, password and user record data. |
|
| public |
async unlinkOAuthProvider(provider: String): Promise Unlink oauth provider |
|
| public |
async verifyUserWithCode(code: String): Promise Verify user by specifying verification code sent by server. |
|
| public |
Retrieves current user record from server. |
|
Public Constructors
public constructor() source
Public Members
Public Methods
public async adminDisableUser(user: Record | String, message: String, expiry: Date): Promise<String> source
Disable user account of a user.
This function is intended for admin use.
Params:
| Name | Type | Attribute | Description |
| user | Record | String | target user |
|
| message | String |
|
message to be shown to user |
| expiry | Date |
|
date and time when the user is automatically enabled |
Return:
| Promise<String> | promise with target user |
public async adminEnableUser(user: Record | String): Promise<String> source
Enable user account of a user.
This function is intended for admin use.
Params:
| Name | Type | Attribute | Description |
| user | Record | String | target user |
Return:
| Promise<String> | promise with target user |
public async adminResetPassword(user: Record | String, newPassword: String): Promise<String> source
Reset user password, require master key.
Params:
| Name | Type | Attribute | Description |
| user | Record | String | target user or user id |
|
| newPassword | String | new password of target user |
Return:
| Promise<String> | promise with target user id |
public async assignUserRole(users: Record[] | String[], roles: Role[] | String[]): Promise<String[]> source
Assigns roles to users.
Return:
| Promise<String[]> | proimse with the target users |
public async authHandler(): Promise source
import {oauthHandler} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Auth flow handler script
Return:
| Promise | promise |
Example:
skygear.auth.oauthHandler().then(...);
public async changePassword(oldPassword: String, newPassword: String, invalidate: Boolean): Promise<Record> source
Changes the password of the current user.
Params:
| Name | Type | Attribute | Description |
| oldPassword | String | old password of current user |
|
| newPassword | String | new password of current user |
|
| invalidate | Boolean |
|
not implemented |
public async fetchUserRole(users: Record[] | String[]): Promise<Object> source
Gets roles of users from server.
Params:
| Name | Type | Attribute | Description |
| users | Record[] | String[] | user records or user ids |
Return:
| Promise<Object> | promise with userIDs-to-roles map |
public async forgotPassword(email: String): Promise source
import {_forgotPassword} from 'skygear-build/packages/skygear-forgot-password/lib/index.js'Send a forgot password email to the email address.
Params:
| Name | Type | Attribute | Description |
| String | target email address |
Return:
| Promise | promise |
Example:
skygear.auth.forgotPassword(email).then(...);
public getLinkRedirectResult(): Promise source
import {getLinkRedirectResult} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Get redirect link result, return user from redirect based login flow if link success, promise resolve with result { result: 'OK' }. if link fail, promise fail with error. if no redirect flow was called, promise resolve with empty result.
Return:
| Promise | promise |
Example:
skygear.auth.getLinkRedirectResult().then(...);
public getLoginRedirectResult(): Promise source
import {getLoginRedirectResult} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Get redirect login result, return user from redirect based login flow if login success, promise resolve with logged in user. if login fail, promise fail with error. if no redirect flow was called, promise resolve with empty result.
Return:
| Promise | promise |
Example:
skygear.auth.getLoginRedirectResult().then(...);
public async getOAuthProviderProfiles(): Promise source
import {getOAuthProviderProfiles} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Get current user's provider profiles, can use for determine user logged in provider
Return:
| Promise | promise |
Example:
skygear.auth.getOAuthProviderProfiles().then(...);
public async iframeHandler(): Promise source
import {iframeHandler} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Iframe handler script. When getLoginRedirectResult is called, sdk will inject an iframe in the document with plugin iframe handler endpoint the endpoint will call this handler. Handler will get the sso result from browser session and post the result back to parnet
Return:
| Promise | promise |
Example:
skygear.auth.iframeHandler().then(...);
public async linkOAuthProviderWithAccessToken(provider: String, accessToken: String): Promise source
import {linkOAuthProviderWithAccessToken} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Link oauth provider with access token
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| accessToken | String | provider app access token |
Return:
| Promise | promise |
Example:
skygear.auth.linkOAuthProviderWithAccessToken(provider, accessToken).then(...);
public async linkOAuthProviderWithPopup(provider: String, options: Object): Promise source
import {linkOAuthProviderWithPopup} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Link oauth provider with popup window
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| options | Object | options for generating auth_url |
|
| options.callbackURL | String | target url for the popup window to post the result message |
|
| options.scope | Array<String> | oauth scopes params |
|
| options.options | Object | add extra query params to provider auth url |
Return:
| Promise | promise |
Example:
skygear.auth.linkOAuthProviderWithPopup('google').then(...);
public linkOAuthProviderWithRedirect(provider: String, options: Object): Promise source
import {linkOAuthProviderWithRedirect} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Link oauth provider with redirect
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| options | Object | options for generating auth_url |
|
| options.callbackURL | String | target url for the popup window to post the result message |
|
| options.scope | Array<String> | oauth scopes params |
|
| options.options | Object | add extra query params to provider auth url |
Return:
| Promise | promise |
Example:
skygear.auth.linkOAuthProviderWithRedirect('google').then(...);
public async login(authData: Object, password: String): Promise<Record> source
Logs in to an existing user account with the specified auth data and password.
Params:
| Name | Type | Attribute | Description |
| authData | Object | unique identifier of the user |
|
| password | String | password of the user |
public async loginOAuthProviderWithAccessToken(provider: String, accessToken: String): Promise source
import {loginOAuthProviderWithAccessToken} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Login oauth provider with access token
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| accessToken | String | provider app access token |
Return:
| Promise | promise |
Example:
skygear.auth.loginOAuthProviderWithAccessToken(provider, accessToken).then(...);
public async loginOAuthProviderWithPopup(provider: String, options: Object): Promise source
import {loginOAuthProviderWithPopup} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Login oauth provider with popup window
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| options | Object | options for generating auth_url |
|
| options.callbackURL | String | target url for the popup window to post the result message |
|
| options.scope | Array<String> | oauth scopes params |
|
| options.options | Object | add extra query params to provider auth url |
Return:
| Promise | promise |
Example:
skygear.auth.loginOAuthProviderWithPopup('google').then(...);
public loginOAuthProviderWithRedirect(provider: String, options: Object): Promise source
import {loginOAuthProviderWithRedirect} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Login oauth provider with redirect
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
|
| options | Object | options for generating auth_url |
|
| options.callbackURL | String | target url for the popup window to post the result message |
|
| options.scope | Array<String> | oauth scopes params |
|
| options.options | Object | add extra query params to provider auth url |
Return:
| Promise | promise |
Example:
skygear.auth.loginOAuthProviderWithRedirect('google').then(...);
public async loginWithCustomToken(token: String): Promise source
import {loginWithCustomToken} from 'skygear-build/packages/skygear-sso/lib/custom_token.js'Login with custom token.
The custom token is typically created on an external server hosting a user database. This server generates the custom token so that the user on an external server can log in to Skygear Server.
Params:
| Name | Type | Attribute | Description |
| token | String | the token string |
Return:
| Promise | promise |
Example:
skygear.auth.loginWithCustomToken('eyXXXXXXXX').then(...);
public async loginWithEmail(email: String, password: String): Promise<Record> source
Logs in to an existing user account with the specified email and password.
Params:
| Name | Type | Attribute | Description |
| String | email of the user |
||
| password | String | password of the user |
public async loginWithProvider(provider: String, authData: Object): Promise<Record> source
Logs in to an existing user account with custom auth provider.
Params:
| Name | Type | Attribute | Description |
| provider | String | provider name |
|
| authData | Object | provider auth data |
public async loginWithUsername(username: String, password: String): Promise<Record> source
Logs in to an existing user account with the specified username and password.
Params:
| Name | Type | Attribute | Description |
| username | String | username of the user |
|
| password | String | password of the user |
public async logout(): Promise source
Logs out the current user of this container.
Return:
| Promise | promise |
public onUserChanged(listener: function()): EventHandle source
Registers listener which user record changed.
Params:
| Name | Type | Attribute | Description |
| listener | function() |
public async requestVerification(recordKey: String): Promise source
import {_requestVerification} from 'skygear-build/packages/skygear-forgot-password/lib/index.js'Request to verify user data.
Params:
| Name | Type | Attribute | Description |
| recordKey | String | record key containing user data to be verified |
Return:
| Promise | promise |
Example:
skygear.auth.requestVerification("email").then(...);
public async resetPassword(userID: String, code: String, expireAt: Number, newPassword: String): Promise source
import {_resetPassword} from 'skygear-build/packages/skygear-forgot-password/lib/index.js'Reset password with a code generated by the server. The code can be retrieved by forgotPassword.
Params:
| Name | Type | Attribute | Description |
| userID | String | target user ID |
|
| code | String | code generated by server |
|
| expireAt | Number | utc timestamp |
|
| newPassword | String | new password of the user |
Return:
| Promise | promise |
Example:
skygear.auth.resetPassword(userID, code, expireAt, newPassword).then(...);
public async revokeUserRole(users: Record[] | String[], roles: Role[] | String[]): Promise<String[]> source
Revokes roles from users.
Return:
| Promise<String[]> | promise with target users |
public async setAdminRole(roles: Role[]): Promise<String[]> source
Defines roles to have admin right.
Params:
| Name | Type | Attribute | Description |
| roles | Role[] | roles to have admin right |
Return:
| Promise<String[]> | promise with role names |
public async setDefaultRole(roles: Role[]): Promise<String[]> source
Sets default roles for new registered users.
Params:
| Name | Type | Attribute | Description |
| roles | Role[] | default roles |
Return:
| Promise<String[]> | promise with role names |
public async signup(authData: Object, password: String, data: Object): Promise<Record> source
Creates a user account with the specified auth data, password and user record data.
Params:
| Name | Type | Attribute | Description |
| authData | Object | unique identifier of the user |
|
| password | String | password of the user |
|
| data | Object |
|
data saved to the user record |
public async signupAnonymously(): Promise<Record> source
Creates an anonymous user account and log in as the created user.
public async signupWithEmail(email: String, password: String, data: Object): Promise<Record> source
Creates a user account with the specified email, password and user record data.
Params:
| Name | Type | Attribute | Description |
| String | email of the user |
||
| password | String | password of the user |
|
| data | Object |
|
data saved to the user record |
public async signupWithUsername(username: String, password: String, data: Object): Promise<Record> source
Creates a user account with the specified username, password and user record data.
Params:
| Name | Type | Attribute | Description |
| username | String | username of the user |
|
| password | String | password of the user |
|
| data | Object |
|
data saved to the user record |
public async unlinkOAuthProvider(provider: String): Promise source
import {unlinkOAuthProvider} from 'skygear-build/packages/skygear-sso/lib/oauth.js'Unlink oauth provider
Params:
| Name | Type | Attribute | Description |
| provider | String | name of provider, e.g. google, facebook |
Return:
| Promise | promise |
Example:
skygear.auth.unlinkOAuthProvider(provider).then(...);
public async verifyUserWithCode(code: String): Promise source
import {_verifyUserWithCode} from 'skygear-build/packages/skygear-forgot-password/lib/index.js'Verify user by specifying verification code sent by server.
Params:
| Name | Type | Attribute | Description |
| code | String | code received from server |
Return:
| Promise | promise |
Example:
skygear.auth.verifyUserWithCode("123456").then(...);
