Skip to content

Instantly share code, notes, and snippets.

@neekey
Created June 21, 2016 10:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neekey/962a52db93a0c641d288c044fc01d921 to your computer and use it in GitHub Desktop.
Save neekey/962a52db93a0c641d288c044fc01d921 to your computer and use it in GitHub Desktop.
parse-server-github-oauth
<!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>
// 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
}
});
@neekey
Copy link
Author

neekey commented Jun 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment