1.0.4 • Published 9 years ago

fireauth v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

FireAuth

An Open Source JavaScript wrapper for Firebase's native and third-party authentication.

Setup

#####HTML

<script src="https://rawgit.com/FireAuth/FireAuth/master/FireAuth-0.0.1.js"></script>

or

<script src="path/to/FireAuth-0.0.1.js"></script>

#####JS var fireAuthInstance = new FireAuth("https://MYFIREBASEREF.firebaseio.com/");

In order to use FireAuth, you must enable User Authentication in your Firebase Authentication Settings

Third Part Authentication Configuration Guides

Facebook
GitHub
Google
Twitter

Classes

Kind: global class
Attribute: string tokenName - name of the token that will be stored in user's browser (This should not be kept default and should remain constant)

new FireAuth(firebaseURL)

ParamTypeDescription
firebaseURLstringThe URL of the Firebase reference.

createUserWithEmail(email, password, callback)

Creates a new Firebase user with Email and Password Authentication.

Kind: global function

ParamTypeDescription
emailstringThe user's email
passwordstringThe user's password
callbackfunctionOptional callback function with parameter userData. (Called upon successful account creation)

Example

fireAuthInstance.createUserWithEmail("john@doe.com", "correcthorsebatterystaple", function(userData){
     // The user creation was successful
     doStuffWith(userData);
})

loginWithEmail(email, password, token, callback)

Logs in a Firebase user with Email and Password Authentication.

Kind: global function

ParamTypeDescription
emailstringThe user's email
passwordstringThe user's password
tokenbooleanTrue to create an auth token, false to not create one.
callbackfunctionOptional callback function with parameter authData. (Called upon successful login)

Example

fireAuthInstance.loginWithEmail("john@doe.com", "correcthorsebatterystaple", false, function(authData){
     // The authentication was successful.
     doStuffWith(authData);
})

changeUserPassword(email, oldPassword, newPassword, callback)

Changes a Firebase user's password.

Kind: global function

ParamTypeDescription
emailstringThe user's email
oldPasswordstringThe user's original password
newPasswordstringThe user's new password
callbackfunctionOptional callback function. (Called upon successful password change)

Example

fireAuthInstance.changeUserPassword("john@doe.com", "correcthorsebatterystaple", "youwillneverguessthis", function(){
     // Password has been changed - handle anything else here.
})

changeUserEmail(oldEmail, newEmail, password, callback)

Changes a Firebase user's email.

Kind: global function

ParamTypeDescription
oldEmailstringThe user's original email
newEmailstringThe user's new email
passwordstringThe user's password
callbackfunctionOptional callback function. (Called upon successful email change)

Example

fireAuthInstance.changeUserEmail("john@doe.com", "jane@doe.com", "correcthorsebatterystaple", function(){
     // Email has been changed - handle anything else here.
})

resetUserPassword(email, callback)

Sends a reset password email to the user.

Kind: global function

ParamTypeDescription
emailstringThe user's email
callbackfunctionOptional callback function. (Called once reset email is sent)

Example

fireAuthInstance.resetUserPassword("john@doe.com", function(){
     // Email has been sent - handle anything else here.
})

deleteUserWithEmail(email, password, callback)

Deletes a Firebase user with Email and Password Authentication.

Kind: global function

ParamTypeDescription
emailstringThe user's email
passwordstringThe user's password
callbackfunctionOptional callback function. (Called upon successful account deletion)

Example

fireAuthInstance.deleteUserWithEmail("john@doe.com", "correcthorsebatterystaple", function(){
     // Successfully deleted user within Firebase - Handle anything else here.
})

loginWithFacebook(redirect, token, sessionTime, permissions, callback)

Logs in a Firebase user with Facebook Authentication. Make sure your application is configured as a Facebook App.

Kind: global function

ParamTypeDescription
redirectbooleanWhether the webpage should redirect the current page. If false the webpage will just open a popup to Facebook.
tokenbooleanTrue to create an auth token, false to not create one.
sessionTimestringIf not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed.
permissionsstringA set of permissions your application may want to access from the user's Facebook account. Certain permissions will have to be approved by the user and Facebook. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Facebook.
callbackfunctionOptional callback function with parameter authData that will not get called if redirect is true. (Called upon successful login) NOTE: Alternatively, this can be done with the "authChangeListener" function

Example

fireAuthInstance.loginWithFacebook(false, true, "default", "email, user_likes" , function(authData){
     // The authentication was successful and opened within a popup.
     doStuffWith(authData);
});

loginWithGithub(redirect, token, sessionTime, permissions, callback)

Logs in a Firebase user with GitHub Authentication. Make sure your application is configured as a GitHub App.

Kind: global function

ParamTypeDescription
redirectbooleanWhether the webpage should redirect the current page. If false the webpage will just open a popup to GitHub.
tokenbooleanTrue to create an auth token, false to not create one.
sessionTimestringIf not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed.
permissionsstringA set of permissions your application may want to access from the user's Github account. Certain permissions will have to be approved by the user and Github. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Github.
callbackfunctionOptional callback function with parameter authData that will not get called if redirect is true. (Called upon successful login) NOTE: Alternatively, this can be done with the "authChangeListener" function

Example

fireAuthInstance.loginWithGithub(false, false, "default", "user, notifications, read:org" , function(authData){
     // The authentication was successful and opened within a popup.
     doStuffWith(authData);
});

loginWithGoogle(redirect, token, sessionTime, permissions, callback)

Logs in a Firebase user with Google Authentication. Make sure your application is configured as a Google App.

Kind: global function

ParamTypeDescription
redirectbooleanWhether the webpage should redirect the current page. If false the webpage will just open a popup to Google.
tokenbooleanTrue to create an auth token, false to not create one.
sessionTimestringIf not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed.
permissionsstringA set of permissions your application may want to access from the user's Google account. Certain permissions will have to be approved by the user and Google. Each of these permissions can be accessed through the callback. Click here to view some of the permissions that can be access from Google.
callbackfunctionOptional callback function with parameter authData that will not get called if redirect is true. (Called upon successful login) NOTE: Alternatively, this can be done with the "authChangeListener" function

Example

fireAuthInstance.loginWithGoogle(true, false "none", "profile, openid" , function(authData){
     // The authentication was successful and opened within a popup.
     doStuffWith(authData);
});

loginWithTwitter(options, callback)

Logs in a Firebase user with Twitter Authentication. Make sure your application is configured as a Twitter App.

Kind: global function

ParamTypeDescription
optionsobjectObject with optional values.
options.redirectbooleanWhether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter.
options.tokenbooleanTrue to create an auth token, false or undefined to not create one.
options.sessionTimestringIf not specified - or set to default - sessions are persisted for as long as you have configured in the Login & Auth tab of your App Dashboard. To limit persistence to the lifetime of the current window, set this to sessionOnly. A value of none will not persist authentication data at all and will end authentication as soon as the page is closed.
callbackfunctionOptional callback function with parameters error and authData that will not get called if redirect is true. (Called upon successful or unsuccessful login)NOTE: Alternatively, this can be done with the "authChangeListener" function

Example

fireAuthInstance.loginWithTwitter(false, true, "sessionOnly", function(authData){
     // The authentication was successful and opened within a popup.
     doStuffWith(authData);
});

logout()

Logs out a user and removes authentication token.

Kind: global function

authChangeListener(onLogin, onLogout)

Event handler checks any changes in user authentication. Can also be used as an alternative to callbacks from other login functions.

Kind: global function

ParamTypeDescription
onLoginfunctionA function with parameter authData that will get called if the user becomes authenticated or is already logged in.
onLogoutfunctionA function with parameter authData that will get called if the user becomes unauthenticated or is already logged out.

Example

fireAuthInstance.authChangeListener(function(authData){
     //The user has logged in
     doStuffWith(authData);
}, function(authData){
     //The user has logged out
     doStuffWith(authData);
})

setTokenName(newTokenName)

Sets the token id or name.

Kind: global function

ParamTypeDescription
newTokenNamestringthe new name of your token.

Example

setTokenName("myTokenForMyFirstWebApp");
Created by Ayush Jain and Rohan Iyer
1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago