Last active
December 6, 2016 15:29
-
-
Save ProbablePrime/653a49e0a52a70dd71f98cf5e22ffe83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Attempt to use OAuth to authenticate with beam. | |
* It is assumed that you are using an IMPLICIT flow here. | |
* | |
* @param {Object} config A config object | |
* @param {String} config.token The implicit OAuth token for this user | |
* @param {BeamClient} beam A beam client instance | |
* @returns {Promise.<user>} | |
*/ | |
function oAuth(config, beam) { | |
beam.use('oauth', { | |
tokens: { | |
access: config.token, | |
expires: Date.now() + (365 * 24 * 60 * 60 * 1000) | |
} | |
}); | |
return beam.request('GET', `users/current`).then(res=> res.body); | |
} | |
/** | |
* Attempt to use password auth to authenticate with beam. | |
* | |
* We advise using OAuth. | |
* | |
* @param {Object} config A config object | |
* @param {String} config.username the username of the account | |
* @param {String} config.password the password of the account | |
* @param {BeamClient} beam A beam client instance | |
* @returns Promise.<user> | |
*/ | |
function password(config, beam) { | |
return beam.use('password', config).attempt().then(res=> res.body); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment