Last active
September 8, 2016 04:40
-
-
Save loganvolkers/83db8b04049b7eb9bc649d14647da5dc to your computer and use it in GitHub Desktop.
Revisions
-
loganvolkers revised this gist
Sep 8, 2016 . 1 changed file with 21 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,27 @@ function doAuth(access_token, ctx, callback) { catch (e) { return callback(new Error('Failed Mailchimp parsing profile JSON' + e + 'body: ' + b)); } // See: https://auth0.com/docs/user-profile/normalized var auth0Normalized = { // "email": profile.email, // "email_verified": true, // "family_name": "Foo", // "gender": "male", // "given_name": "John", // "identities": [{ // "provider": "Mailchimp", // "user_id": profile.account_id, // "connection": "MailchimpDev", // "isSocial": true // }], // "locale": "en", "name": profile.account_name, "nickname": profile.username, // "picture": "https://lh4.googleusercontent.com/-OdsbOXom9qE/AAAAAAAAAAI/AAAAAAAAADU/_j8SzYTOJ4I/photo.jpg", "user_id": profile.account_id }; var final = Object.assign({},profile,auth0Normalized); callback(null, final); }); }); } -
loganvolkers revised this gist
Sep 8, 2016 . 1 changed file with 35 additions and 22 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,39 @@ function doAuth(access_token, ctx, callback) { var opts = { 'headers': { 'Authorization': 'OAuth ' + access_token, 'Accept': 'application/json', 'User-Agent': 'Auth0' } }; request.get('https://login.mailchimp.com/oauth2/metadata', opts, function(e, r, b) { if (e) { return callback(new Error('Failed Mailchimp Metadata Lookup' + e)); } if (r.statusCode !== 200) { return callback(new Error('Failed Mailchimp Metadata Lookup StatusCode:' + r.statusCode)); } try { var meta = JSON.parse(b); } catch (e) { return callback(new Error('Failed Mailchimp Metadata parsing JSON' + e)); } request.get(meta.api_endpoint + '/3.0', opts, function(e, r, b) { if (e) { return callback(new Error('Failed Mailchimp User/Account Lookup' + e)); } if (r.statusCode !== 200) { return callback(new Error('Failed Mailchimp User/Account Lookup StatusCode:' + r.statusCode)); } try { var profile = JSON.parse(b); } catch (e) { return callback(new Error('Failed Mailchimp parsing profile JSON' + e + 'body: ' + b)); } callback(null, profile); }); }); } -
loganvolkers revised this gist
Sep 8, 2016 . 1 changed file with 17 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,25 @@ function(access_token, ctx, callback) { request.get('https://login.mailchimp.com/oauth2/metadata', { 'headers': {\ 'Authorization': 'OAuth ' + access_token, 'Accept': 'application/json', 'User-Agent': 'Auth0' } }, function(e,r,b){ if( e ) return cb(e); if( r.statusCode !== 200 ) return callback(new Error('StatusCode:'+r.statusCode)); var meta = JSON.parse(b); request.get(meta.api_endpoint, { 'headers': {\ 'Authorization': 'OAuth ' + access_token, 'Accept': 'application/json', 'User-Agent': 'Auth0' } }, function(e,r,b){ if( e ) return cb(e); if( r.statusCode !== 200 ) return callback(new Error('StatusCode:'+r.statusCode)); callback(null,JSON.parse(b)); }); }); } -
loganvolkers created this gist
Sep 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ function(access_token, ctx, callback) { request.get('https://login.mailchimp.com/oauth2/metadata', { 'headers': {\ 'Authorization': 'Bearer ' + access_token, 'User-Agent': 'Auth0' } }, function(e,r,b){ if( e ) return cb(e); if( r.statusCode !== 200 ) return callback(new Error('StatusCode:'+r.statusCode)); callback(null,JSON.parse(b)); }); throw new Error("Context:"+ JSON.stringify(ctx)); }