mirror of
https://github.com/moparisthebest/mail
synced 2025-02-07 02:20:14 -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) {
|
self.execute = function(cmd, args, callback) {
|
||||||
if (cmd === 'login') {
|
if (cmd === 'login') {
|
||||||
// login user
|
// login user
|
||||||
fetchOAuthToken(args.userId, args.password, function(err) {
|
fetchOAuthToken(args.password, function(err, userId) {
|
||||||
callback({
|
callback({
|
||||||
err: err
|
err: err,
|
||||||
|
userId: userId
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,13 +93,32 @@ define(['jquery', 'ImapClient', 'SmtpClient', 'js/dao/email-dao', 'js/dao/keycha
|
|||||||
// Helper methods
|
// Helper methods
|
||||||
//
|
//
|
||||||
|
|
||||||
function fetchOAuthToken(userId, password, callback) {
|
function fetchOAuthToken(password, callback) {
|
||||||
// get OAuth Token from chrome
|
// get OAuth Token from chrome
|
||||||
chrome.identity.getAuthToken({
|
chrome.identity.getAuthToken({
|
||||||
'interactive': true
|
'interactive': true
|
||||||
},
|
},
|
||||||
function(token) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location = '#accounts/' + userId + '/folders';
|
window.location = '#accounts/' + resArgs.userId + '/folders';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"oauth2": {
|
"oauth2": {
|
||||||
"client_id": "440907777130.apps.googleusercontent.com",
|
"client_id": "440907777130.apps.googleusercontent.com",
|
||||||
"scopes": [
|
"scopes": [
|
||||||
|
"https://www.googleapis.com/auth/userinfo.email",
|
||||||
"https://mail.google.com/"
|
"https://mail.google.com/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<div id="loginForm">
|
<div id="loginForm">
|
||||||
<h3>Please sign in</h3>
|
<h3>Please sign in</h3>
|
||||||
<label for="userId" class="ui-hidden-accessible">Username:</label>
|
<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>
|
<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="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">
|
<input type="button" data-theme="b" data-icon="check" id="loginBtn" value="Sign in">
|
||||||
|
Loading…
Reference in New Issue
Block a user