mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Draft code for #1645
This commit is contained in:
parent
9f3f41f308
commit
7f7ee97106
2 changed files with 274 additions and 0 deletions
50
plugins/login-o365/LoginOAuth2.js
Normal file
50
plugins/login-o365/LoginOAuth2.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
(rl => {
|
||||
const client_id = rl.pluginSettingsGet('login-gmail', 'client_id'),
|
||||
login = () => {
|
||||
document.location = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?' + (new URLSearchParams({
|
||||
response_type: 'code',
|
||||
client_id: client_id,
|
||||
redirect_uri: document.location.href + '?LoginGMail',
|
||||
scope: [
|
||||
// Associate personal info
|
||||
'openid',
|
||||
'offline_access',
|
||||
'email',
|
||||
'profile',
|
||||
// Access IMAP and SMTP through OAUTH
|
||||
'https://graph.microsoft.com/IMAP.AccessAsUser.All',
|
||||
'https://graph.microsoft.com/Mail.Send'
|
||||
/* // Legacy:
|
||||
'https://outlook.office.com/SMTP.Send',
|
||||
'https://outlook.office.com/IMAP.AccessAsUser.All'
|
||||
*/
|
||||
].join(' '),
|
||||
state: 'gmail', // + rl.settings.app('token') + localStorage.getItem('smctoken')
|
||||
// Force authorize screen, so we always get a refresh_token
|
||||
access_type: 'offline',
|
||||
prompt: 'consent'
|
||||
}));
|
||||
};
|
||||
|
||||
if (client_id) {
|
||||
addEventListener('sm-user-login', e => {
|
||||
if (event.detail.get('Email').includes('@gmail.com')) {
|
||||
e.preventDefault();
|
||||
login();
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener('rl-view-model', e => {
|
||||
if ('Login' === e.detail.viewModelTemplateID) {
|
||||
const
|
||||
container = e.detail.viewModelDom.querySelector('#plugin-Login-BottomControlGroup'),
|
||||
btn = Element.fromHTML('<button type="button">Outlook</button>'),
|
||||
div = Element.fromHTML('<div class="controls"></div>');
|
||||
btn.onclick = login;
|
||||
div.append(btn);
|
||||
container && container.append(div);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})(window.rl);
|
||||
Loading…
Add table
Add a link
Reference in a new issue