-
-
Save scopevale/27ed323158860e587581 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| * quickstart.js | |
| * ~~~~~~~~~~~~~ | |
| * | |
| * Code from the Stormpath Node.js Quickstart: | |
| * http://docs.stormpath.com/nodejs/quickstart/ | |
| * | |
| * You can run this code by typing: | |
| * | |
| * $ node quickstart.js | |
| * | |
| * In your terminal. | |
| * | |
| * Questions? Email us! [email protected] | |
| */ | |
| var stormpath = require('stormpath'); | |
| var client = null; | |
| var homedir = (process.platform === 'win32') ? process.env.HOMEPATH : process.env.HOME; | |
| var keyfile = homedir + '/.stormpath/apiKey.properties'; | |
| // Create a Stormpath Client. | |
| stormpath.loadApiKey(keyfile, function apiKeyFileLoaded(err, apiKey) { | |
| if (err) throw err; | |
| client = new stormpath.Client({apiKey: apiKey}); | |
| console.log('Created client!'); | |
| var app = { | |
| name: 'My Awesome Application', | |
| description: 'Super awesome!', | |
| }; | |
| // Create a Stormpath Application. | |
| client.createApplication(app, {createDirectory: true}, function(err, app) { | |
| if (err) throw err; | |
| console.log('Application created!'); | |
| var account = { | |
| givenName: 'Joe', | |
| surname: 'Stormtrooper', | |
| username: 'tk455', | |
| email: '[email protected]', | |
| password: 'Changeme1', | |
| customData: { | |
| favoriteColor: 'white', | |
| }, | |
| }; | |
| // Create a Stormpath Account. | |
| app.createAccount(account, function(err, account) { | |
| if (err) throw err; | |
| console.log('Account created!'); | |
| console.log('Account givenName: ' + account.givenName); | |
| console.log('Account surname: ' + account.surname); | |
| // Search for Account by email. | |
| app.getAccounts({email: '[email protected]'}, function(err, accounts) { | |
| if (err) throw err; | |
| accounts.each(function (err, account, index) { | |
| console.log('Found account using search by email!'); | |
| }); | |
| }); | |
| // Authenticate Account by username / password. | |
| app.authenticateAccount({ | |
| username: 'tk455', | |
| password: 'Changeme1', | |
| }, function (err, result) { | |
| if (err) throw err; | |
| console.log('Successfully authenticated account using username!'); | |
| }); | |
| // Authenticate Account by email / password. | |
| app.authenticateAccount({ | |
| username: '[email protected]', | |
| password: 'Changeme1', | |
| }, function (err, result) { | |
| if (err) throw err; | |
| console.log('Successfully authenticated account using email!'); | |
| }); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment