fireauth
v1.0.4
Published
##### An Open Source JavaScript wrapper for Firebase's native and third-party authentication.
Downloads
16
Maintainers
Readme
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
GitHub
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)
| Param | Type | Description | | --- | --- | --- | | firebaseURL | string | The URL of the Firebase reference. |
createUserWithEmail(email, password, callback)
Creates a new Firebase user with Email and Password Authentication.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | email | string | The user's email | | password | string | The user's password | | callback | function | Optional callback function with parameter userData. (Called upon successful account creation) |
Example
fireAuthInstance.createUserWithEmail("[email protected]", "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
| Param | Type | Description | | --- | --- | --- | | email | string | The user's email | | password | string | The user's password | | token | boolean | True to create an auth token, false to not create one. | | callback | function | Optional callback function with parameter authData. (Called upon successful login) |
Example
fireAuthInstance.loginWithEmail("[email protected]", "correcthorsebatterystaple", false, function(authData){
// The authentication was successful.
doStuffWith(authData);
})
changeUserPassword(email, oldPassword, newPassword, callback)
Changes a Firebase user's password.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | email | string | The user's email | | oldPassword | string | The user's original password | | newPassword | string | The user's new password | | callback | function | Optional callback function. (Called upon successful password change) |
Example
fireAuthInstance.changeUserPassword("[email protected]", "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
| Param | Type | Description | | --- | --- | --- | | oldEmail | string | The user's original email | | newEmail | string | The user's new email | | password | string | The user's password | | callback | function | Optional callback function. (Called upon successful email change) |
Example
fireAuthInstance.changeUserEmail("[email protected]", "[email protected]", "correcthorsebatterystaple", function(){
// Email has been changed - handle anything else here.
})
resetUserPassword(email, callback)
Sends a reset password email to the user.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | email | string | The user's email | | callback | function | Optional callback function. (Called once reset email is sent) |
Example
fireAuthInstance.resetUserPassword("[email protected]", 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
| Param | Type | Description | | --- | --- | --- | | email | string | The user's email | | password | string | The user's password | | callback | function | Optional callback function. (Called upon successful account deletion) |
Example
fireAuthInstance.deleteUserWithEmail("[email protected]", "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
| Param | Type | Description | | --- | --- | --- | | redirect | boolean | Whether the webpage should redirect the current page. If false the webpage will just open a popup to Facebook. | | token | boolean | True to create an auth token, false to not create one. | | sessionTime | string | If 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. | | permissions | string | A 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. | | callback | function | Optional 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
| Param | Type | Description | | --- | --- | --- | | redirect | boolean | Whether the webpage should redirect the current page. If false the webpage will just open a popup to GitHub. | | token | boolean | True to create an auth token, false to not create one. | | sessionTime | string | If 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. | | permissions | string | A 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. | | callback | function | Optional 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
| Param | Type | Description | | --- | --- | --- | | redirect | boolean | Whether the webpage should redirect the current page. If false the webpage will just open a popup to Google. | | token | boolean | True to create an auth token, false to not create one. | | sessionTime | string | If 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. | | permissions | string | A 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. | | callback | function | Optional 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
| Param | Type | Description | | --- | --- | --- | | options | object | Object with optional values. | | options.redirect | boolean | Whether the webpage should redirect the current page. If false or not defined the webpage will just open a popup to Twitter. | | options.token | boolean | True to create an auth token, false or undefined to not create one. | | options.sessionTime | string | If 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. | | callback | function | Optional 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
| Param | Type | Description | | --- | --- | --- | | onLogin | function | A function with parameter authData that will get called if the user becomes authenticated or is already logged in. | | onLogout | function | A 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
| Param | Type | Description | | --- | --- | --- | | newTokenName | string | the new name of your token. |
Example
setTokenName("myTokenForMyFirstWebApp");