Created
June 21, 2016 10:38
-
-
Save neekey/962a52db93a0c641d288c044fc01d921 to your computer and use it in GitHub Desktop.
parse-server-github-oauth
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script src="http://www.parsecdn.com/js/parse-latest.js"></script> | |
<script src="https://adodson.com/hello.js/dist/hello.all.min.js"></script> | |
</head> | |
<body> | |
<a onclick="login()">login</a> | |
<script> | |
Parse.initialize( 'myAppId'); | |
Parse.serverURL = 'http://localhost:1337/parse'; | |
// Create a instagram provider | |
var provider = { | |
getAuthType() { | |
return 'github'; | |
} | |
}; | |
hello.init({ | |
github: 'you client id' | |
}); | |
function login(){ | |
hello.login('github').then(function( auth_data ) { | |
console.log('You are signed in to github', auth_data ); | |
// get user profile | |
return hello('github').api('me').then(function( me ){ | |
console.log( 'get my profile', me ); | |
// Login the user with the Github provider | |
Parse.User.logInWith(provider, { | |
authData: { | |
access_token: auth_data.authResponse.access_token, | |
id: me.id | |
} | |
}).then( function( user ) { | |
console.log(user); | |
}, function( error ) { | |
console.log( error ); | |
}); | |
}); | |
}, function(e) { | |
alert('Signin error: ' + e.error.message); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
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
// you need to enable github in your parse server | |
var api = new ParseServer({ | |
databaseURI: databaseUri || 'mongodb://localhost:27017/dev', | |
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', | |
appId: process.env.APP_ID || 'myAppId', | |
masterKey: process.env.MASTER_KEY || 'myMasterKey', //Add your master key here. Keep it secret! | |
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', | |
auth: { | |
github: true | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
parse-community/Parse-SDK-JS#246