mirror of
https://github.com/moparisthebest/mail
synced 2025-01-30 22:50:17 -05:00
fetching email address from tokeninfo oauth endpoint works
This commit is contained in:
parent
7f42722699
commit
9b6ea304f7
@ -39,9 +39,10 @@ define(['jquery', 'ImapClient', 'SmtpClient', 'js/dao/email-dao', 'js/dao/keycha
|
||||
self.execute = function(cmd, args, callback) {
|
||||
if (cmd === 'login') {
|
||||
// login user
|
||||
fetchOAuthToken(args.userId, args.password, function(err) {
|
||||
fetchOAuthToken(args.password, function(err, userId) {
|
||||
callback({
|
||||
err: err
|
||||
err: err,
|
||||
userId: userId
|
||||
});
|
||||
});
|
||||
|
||||
@ -92,13 +93,32 @@ define(['jquery', 'ImapClient', 'SmtpClient', 'js/dao/email-dao', 'js/dao/keycha
|
||||
// Helper methods
|
||||
//
|
||||
|
||||
function fetchOAuthToken(userId, password, callback) {
|
||||
function fetchOAuthToken(password, callback) {
|
||||
// get OAuth Token from chrome
|
||||
chrome.identity.getAuthToken({
|
||||
'interactive': true
|
||||
},
|
||||
function(token) {
|
||||
login(userId, password, token, callback);
|
||||
// fetch gmail user's email address from the Google Authorization Server endpoint
|
||||
$.ajax({
|
||||
url: 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + token,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(info) {
|
||||
// login using the received email address
|
||||
login(info.email, password, token, function(err) {
|
||||
// send email address to sandbox
|
||||
callback(err, info.email);
|
||||
});
|
||||
},
|
||||
error: function(xhr, textStatus, err) {
|
||||
callback({
|
||||
errMsg: xhr.status + ': ' + xhr.statusText,
|
||||
err: err
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
|
||||
return;
|
||||
}
|
||||
|
||||
window.location = '#accounts/' + userId + '/folders';
|
||||
window.location = '#accounts/' + resArgs.userId + '/folders';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -17,6 +17,7 @@
|
||||
"oauth2": {
|
||||
"client_id": "440907777130.apps.googleusercontent.com",
|
||||
"scopes": [
|
||||
"https://www.googleapis.com/auth/userinfo.email",
|
||||
"https://mail.google.com/"
|
||||
]
|
||||
},
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div id="loginForm">
|
||||
<h3>Please sign in</h3>
|
||||
<label for="userId" class="ui-hidden-accessible">Username:</label>
|
||||
<input type="email" name="user" id="userId" value="safewithme.testuser@gmail.com" placeholder="user" data-theme="a">
|
||||
<input type="email" name="user" id="userId" value="" placeholder="user" data-theme="a">
|
||||
<label for="password" class="ui-hidden-accessible">Password:</label>
|
||||
<input type="password" name="pass" id="password" value="passphrase" placeholder="password" data-theme="a">
|
||||
<input type="button" data-theme="b" data-icon="check" id="loginBtn" value="Sign in">
|
||||
|
Loading…
Reference in New Issue
Block a user