mirror of
https://gitee.com/mafgwo/stackedit
synced 2024-11-16 03:32:40 +08:00
Added oauth2 callback
This commit is contained in:
parent
d09375dc4c
commit
855e6cb056
|
@ -59,8 +59,8 @@ app.use(devMiddleware)
|
|||
app.use(hotMiddleware)
|
||||
|
||||
// serve pure static assets
|
||||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
|
||||
app.use(staticPath, express.static('./static'))
|
||||
// var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
|
||||
app.use(express.static('./static'))
|
||||
|
||||
var uri = 'http://localhost:' + port
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>my-project</title>
|
||||
<title>StackEdit</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "my-project",
|
||||
"name": "StackEdit",
|
||||
"version": "1.0.0",
|
||||
"description": "A Vue.js project",
|
||||
"author": "",
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
<div>Sign in with Google</div>
|
||||
<span>Have all your files and settings backed up and synced.</span>
|
||||
</side-bar-item>
|
||||
<side-bar-item @click.native="signin">
|
||||
<icon-login slot="icon"></icon-login>
|
||||
<div>Sign in on CouchDB</div>
|
||||
<span>Save and collaborate on a CouchDB hosted by you.</span>
|
||||
</side-bar-item>
|
||||
<side-bar-item @click.native="panel = 'toc'">
|
||||
<icon-toc slot="icon"></icon-toc>
|
||||
Table of contents
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import utils from './utils';
|
||||
import store from '../store';
|
||||
|
||||
const googleClientId = '241271498917-t4t7d07qis7oc0ahaskbif3ft6tk63cd.apps.googleusercontent.com';
|
||||
const appUri = 'http://localhost:8080/';
|
||||
|
@ -12,8 +13,8 @@ export default {
|
|||
const state = utils.uid();
|
||||
let authorizeUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'client_id', googleClientId);
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'response_type', 'code');
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'redirect_uri', `${appUri}oauth2/google/callback`);
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'response_type', 'token');
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'redirect_uri', `${appUri}oauth2/callback.html`);
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'state', state);
|
||||
if (googleAppsDomain) {
|
||||
authorizeUrl = utils.addQueryParam(authorizeUrl, 'scope', 'openid email');
|
||||
|
@ -33,8 +34,14 @@ export default {
|
|||
&& event.data.state === state
|
||||
) {
|
||||
this.cleanOauth2Context();
|
||||
console.log(event.data);
|
||||
resolve();
|
||||
if (event.data.accessToken) {
|
||||
store.dispatch('data/patchTokens', {
|
||||
googleToken: {
|
||||
accessToken: event.data.accessToken,
|
||||
},
|
||||
});
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', msgHandler);
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
import moduleTemplate from './moduleTemplate';
|
||||
import defaultLocalSettings from '../../data/defaultLocalSettings';
|
||||
|
||||
const empty = (id) => {
|
||||
switch (id) {
|
||||
case 'localSettings':
|
||||
return defaultLocalSettings();
|
||||
default:
|
||||
return { id, updated: 0 };
|
||||
}
|
||||
};
|
||||
const module = moduleTemplate(empty);
|
||||
|
||||
const getter = id => state => state.itemMap[id] || empty(id);
|
||||
|
||||
const localSettingsToggler = propertyName => ({ getters, dispatch }, value) => {
|
||||
dispatch('patchLocalSettings', {
|
||||
[propertyName]: value === undefined ? !getters.localSettings[propertyName] : value,
|
||||
});
|
||||
};
|
||||
|
||||
const module = moduleTemplate((id) => {
|
||||
switch (id) {
|
||||
case 'localSettings':
|
||||
return defaultLocalSettings();
|
||||
default:
|
||||
throw new Error(`Unknown data id ${id}`);
|
||||
}
|
||||
});
|
||||
|
||||
module.getters = {
|
||||
...module.getters,
|
||||
localSettings: state => state.itemMap.localSettings || defaultLocalSettings(),
|
||||
localSettings: getter('localSettings'),
|
||||
tokens: getter('tokens'),
|
||||
};
|
||||
|
||||
module.actions = {
|
||||
|
@ -29,6 +33,12 @@ module.actions = {
|
|||
id: 'localSettings',
|
||||
});
|
||||
},
|
||||
patchTokens({ getters, commit }, value) {
|
||||
commit('patchOrSetItem', {
|
||||
...value,
|
||||
id: 'tokens',
|
||||
});
|
||||
},
|
||||
toggleNavigationBar: localSettingsToggler('showNavigationBar'),
|
||||
toggleEditor: localSettingsToggler('showEditor'),
|
||||
toggleSidePreview: localSettingsToggler('showSidePreview'),
|
||||
|
|
28
static/oauth2/callback.html
Normal file
28
static/oauth2/callback.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script>
|
||||
var state;
|
||||
var accessToken;
|
||||
function parse(search) {
|
||||
(search || '').slice(1).split('&').forEach(function (param) {
|
||||
var split = param.split('=');
|
||||
var key = decodeURIComponent(split.shift());
|
||||
var value = decodeURIComponent(split.join('='));
|
||||
if (key === 'state') {
|
||||
state = value;
|
||||
} else if (key === 'access_token') {
|
||||
accessToken = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
parse(location.search);
|
||||
parse(location.hash);
|
||||
var origin = location.protocol + '//' + location.host;
|
||||
opener.postMessage({
|
||||
state: state,
|
||||
accessToken: accessToken
|
||||
}, origin);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user