Home Reference Source
public class | source

AuthContainer

Direct Subclass:

CloudCodeAuthContainer

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

Get redirect link result, return user from redirect based login flow if link success, promise resolve with result { result: 'OK' }.

public

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

async login(authData: Object, password: String): Promise<Record>

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

async signup(authData: Object, password: String, data: Object): Promise<Record>

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

async whoami(): Promise<Record>

Retrieves current user record from server.

Public Constructors

public constructor() source

Public Members

public get accessToken: String source

Current access token

public get currentUser: Record source

Currently logged-in user

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:

NameTypeAttributeDescription
user Record | String

target user

message String
  • optional

message to be shown to user

expiry Date
  • optional

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
users Record[] | String[]

target users

roles Role[] | String[]

roles to be assigned

Return:

Promise<String[]>

proimse with the target users

public async authHandler(): Promise source

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:

NameTypeAttributeDescription
oldPassword String

old password of current user

newPassword String

new password of current user

invalidate Boolean
  • optional
  • default: false

not implemented

Return:

Promise<Record>

promise with current user record

public async fetchUserRole(users: Record[] | String[]): Promise<Object> source

Gets roles of users from server.

Params:

NameTypeAttributeDescription
users Record[] | String[]

user records or user ids

Return:

Promise<Object>

promise with userIDs-to-roles map

public async forgotPassword(email: String): Promise source

Send a forgot password email to the email address.

Params:

NameTypeAttributeDescription
email 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

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
authData Object

unique identifier of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
email String

email of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

public async loginWithProvider(provider: String, authData: Object): Promise<Record> source

Logs in to an existing user account with custom auth provider.

Params:

NameTypeAttributeDescription
provider String

provider name

authData Object

provider auth data

Return:

Promise<Record>

promise with the logged in user record

public async loginWithUsername(username: String, password: String): Promise<Record> source

Logs in to an existing user account with the specified username and password.

Params:

NameTypeAttributeDescription
username String

username of the user

password String

password of the user

Return:

Promise<Record>

promise with the logged in user record

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:

NameTypeAttributeDescription
listener function()

Return:

EventHandle

public async requestVerification(recordKey: String): Promise source

Request to verify user data.

Params:

NameTypeAttributeDescription
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

Reset password with a code generated by the server. The code can be retrieved by forgotPassword.

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
users Record[] | String[]

target users

roles Role[] | String[]

roles to be revoked

Return:

Promise<String[]>

promise with target users

public async setAdminRole(roles: Role[]): Promise<String[]> source

Defines roles to have admin right.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
authData Object

unique identifier of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with created user record

public async signupAnonymously(): Promise<Record> source

Creates an anonymous user account and log in as the created user.

Return:

Promise<Record>

promise with the created user record

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:

NameTypeAttributeDescription
email String

email of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with the created 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:

NameTypeAttributeDescription
username String

username of the user

password String

password of the user

data Object
  • optional
  • default: {}

data saved to the user record

Return:

Promise<Record>

promise with the created user record

public async unlinkOAuthProvider(provider: String): Promise source

import {unlinkOAuthProvider} from 'skygear-build/packages/skygear-sso/lib/oauth.js'

Unlink oauth provider

Params:

NameTypeAttributeDescription
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

Verify user by specifying verification code sent by server.

Params:

NameTypeAttributeDescription
code String

code received from server

Return:

Promise

promise

Example:

skygear.auth.verifyUserWithCode("123456").then(...);

public async whoami(): Promise<Record> source

Retrieves current user record from server.

Return:

Promise<Record>

promise with current user record