-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from zhuowenli/dev
✨ 支持折叠书签栏
- Loading branch information
Showing
15 changed files
with
165 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* @Author: 卓文理 | ||
* @Email: [email protected] | ||
* @Date: 2018-05-06 13:21:58 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
import Router from 'koa-router'; | ||
import axios from 'axios'; | ||
|
||
const router = new Router(); | ||
const id = process.env.CLIENT_ID; | ||
const sercet = process.env.CLIENT_SERECT; | ||
|
||
router.get('/github/login', async (ctx, next) => { | ||
// 去到github授权页 | ||
const dataStr = (new Date()).valueOf(); | ||
const path = `https://github.com/login/oauth/authorize?client_id=${id}&scope=['user']&state=${dataStr}`; | ||
|
||
ctx.redirect(path); // 送到授权的中间页 | ||
}); | ||
|
||
// 添加 | ||
router.get('/github/callback', async (ctx, next) => { | ||
const code = ctx.query.code; | ||
const data = await axios({ // 没有fetch,需要装node-fetch | ||
url: 'https://github.com/login/oauth/access_token', | ||
method: 'post', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
data: { | ||
client_id: id, | ||
client_secret: sercet, | ||
code | ||
}, | ||
}).then(res => res.data); | ||
|
||
const args = data.split('&'); | ||
const arg = args[0].split('='); | ||
const access_token = arg[1]; | ||
|
||
const url = `https://api.github.com/user?access_token=${access_token}`; // token就是oauth令牌环 | ||
|
||
await axios.get(url) | ||
.then(res => { | ||
ctx.body = res.data; | ||
}); | ||
}); | ||
|
||
export default router; |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"name": "githuber", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"main": "index.js", | ||
"repository": "[email protected]:zhuowenli/githuber.git", | ||
"author": "卓文理 <[email protected]>", | ||
"license": "Mozilla Public License Version 2.0", | ||
"scripts": { | ||
"dev": "poi --dev", | ||
"watch": "poi watch", | ||
"build": "cross-env NODE_ENV=production poi build", | ||
"build": "rm -rf dist && cross-env NODE_ENV=production poi build", | ||
"start": "pm2 start ./app/index.js --name 'githuber-server'", | ||
"restart": "pm2 restart githuber-server", | ||
"nodemon": "nodemon --watch app ./app/index.js", | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.