auth

auth

Members

(static) sync

Source:
Helper function to resync the user's session from the server. This is often used when first loading a webpage or app just to see if the user's permissions have changed since the user first logged in from the FluroAuth service itself

Methods

(static) addEventListener(event, callback)

Source:
Adds a callback that will be triggered whenever the specified event occurs
Example
//Listen for when the user session changes
fluro.auth.addEventListener('change', function(userSession) {})
Parameters:
Name Type Description
event String The event to listen for
callback function The function to fire when this event is triggered

(static) changeAccount(accountID, options) → {Promise}

Source:
Retrieves a new session object for a Fluro global user for a specified account This will only work if the user has a persona in that account
Example
fluro.auth.changeAccount('5be504eabf33991239599d63').then(function(userSession) {
    //New user session will be set automatically
    var newUserSession = fluro.auth.getCurrentUser();
})
fluro.auth.changeAccount('5be504eabf33991239599d63', {disableAutoAuthenticate:true}).then(function(userSession) {
    //Set the session manually
    fluro.auth.set(userSession)
})
Parameters:
Name Type Description
accountID String The _id of the account you wish to log in to
options Object
Properties
Name Type Description
disableAutoAuthenticate Object By default this function will set the current user session to account you are changing in to. If you want to generate the session without affecting your current session you can set disableAutoAuthenticate to true
Returns:
Resolves to the user session object, or rejects with the responding error
Type
Promise

(static) getCurrentToken() → {String}

Source:
Returns the current user's access token
Returns:
The Fluro access token for the current user session
Type
String

(static) getCurrentUser() → {Object}

Source:
Returns the current user's session data
Returns:
The current user session
Type
Object

(static) impersonate(personaID, options) → {Promise}

Source:
Impersonates a persona and sets the current session to match the specified persona's context
Example
fluro.auth.impersonate('5be504eabf33991239599d63')
.then(function(userSession) {
    //New user session will be set automatically
    var newUserSession = fluro.auth.getCurrentUser();
})
Parameters:
Name Type Description
personaID String The _id of the persona you wish to impersonate
options Object
Returns:
Resolves to the user session object, or rejects with the responding error
Type
Promise

(static) login(credentials, options) → {Promise}

Source:
Logs the user in to Fluro and returns a new user session
Parameters:
Name Type Description
credentials Object
Properties
Name Type Description
username String The email address of the user to login as
password String The password for the user
options Object Extra options and configuration for the request
Properties
Name Type Description
disableAutoAuthenticate Object Disable automatic authentication, if true, will not set the current user session
application Object Whether to attempt to login to the current application as a managed user persona, if not set will login as a global Fluro user
Returns:
Returns a promise that either resolves with the logged in user session, or rejects with the responding error from the server
Type
Promise

(static) logout()

Source:
Deletes the user session object, clears all Fluro caches and tokens from memory
Example
fluro.auth.logout()

(static) refreshAccessToken(refreshToken, isManagedSession) → {Promise}

Source:
Helper function to refresh an access token for an authenticated user session. This is usually handled automatically from the FluroAuth service itself
Parameters:
Name Type Description
refreshToken String The refresh token to reactivate
isManagedSession Boolean Whether or not the refresh token is for a managed persona session or a global Fluro user session
Returns:
A promise that either resolves with the refreshed token details or rejects with the responding error from the server
Type
Promise

(static) removeAllListeners()

Source:
Removes all listening callbacks for all events
Example
fluro.auth.removeAllListeners()

(static) removeEventListener(event, callback)

Source:
Removes all a callback from the listener list
Example
//Stop listening for the change event
fluro.auth.removeEventListener('change', myFunction)
Parameters:
Name Type Description
event String The event to stop listening for
callback function The function to remove from the listener list

(static) retrieveUserFromResetToken(token, options) → {Promise}

Source:
Retrieves a user's details by providing a password reset token
Parameters:
Name Type Description
token String The password reset token that was sent to the user's email address
options Object other options for the request
Properties
Name Type Description
application Boolean If true will retrieve in the context of a managed persona in the same account as the current application. If not specified or false, will assume it's a Fluro global user that is resetting their password.
Returns:
Returns a promise that resolves with the reset session details
Type
Promise

(static) sendResetPasswordRequest(body, options) → {Promise}

Source:
Triggers a new Reset Password email request to the specified user.
Parameters:
Name Type Description
body Object
Properties
Name Type Description
username String The email address of the user to reset the password for
redirect String If the request is in the context of a managed user persona authenticated with an application, then you need to provide the url to direct the user to when they click the reset password link This is usually something like '/reset' for the current application, when the user clicks the link the reset token will be appended with ?token=RESET_TOKEN and your application should be ready on that url to handle the token and allow the user to use the token to reset their password
options Object Extra options and configuration for the request
Properties
Name Type Description
application Boolean If true will send a reset email from the context of a managed persona in the same account as the current application. If not specified or false, will send a password reset request for a global Fluro user account.
Returns:
Returns a promise that either resolves if the password request was sent, or rejects if an error occurred
Type
Promise

(static) set(user)

Source:
Sets the current user data, often from localStorage or after new session data has been generated from the server after signing in
Example
FluroAsset.set({firstName:'Jeff', lastName:'Andrews', ...})
Parameters:
Name Type Description
user Object The user session object

(static) signup(credentials, options) → {Promise}

Source:
Signs up a new user to the current application, this will create a new managed user persona and automatically log in as that persona in the current application context. This function will only work when called in context of an application with the 'Application Token' authentication style. It will create a new user persona in the account of the application and return a session with all of the application's permissions and application's logged in user permissions
Parameters:
Name Type Description
credentials Object
Properties
Name Type Description
firstName String The first name for the new user persona
lastName String The last name for the new user persona
username String The email address for the new persona
password String The password to set for the new persona
confirmPassword String A double check to confirm the new password for the persona
options Object Extra options and configuration for the request
Returns:
Returns a promise that either resolves to the new authenticated session, or rejects with the responding error from the server
Type
Promise

(static) updateUserWithToken(token, body, options) → {Promise}

Source:
Updates a user's details including password by providing a password reset token
Parameters:
Name Type Description
token String The password reset token that was sent to the user's email address
body Object The details to change for the user
options Object other options for the request
Returns:
Returns a promise that resolves with the reset session details
Type
Promise