Ai
1 Star 0 Fork 0

codingchengdu/egg-oauth2-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
oauth.js 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
Azard 提交于 2017-12-13 21:38 +08:00 . 2.1.0: compatible with egg 2.x
'use strict';
const path = require('path');
const nconf = require('nconf');
module.exports = app => {
// Mock Data
nconf.use('file', {
file: path.join(app.config.baseDir, 'app/mock/db.json'),
});
class Model {
constructor(ctx) {
this.ctx = ctx;
}
async getClient(clientId, clientSecret) {
const client = nconf.get('client');
if (clientId !== client.clientId || clientSecret !== client.clientSecret) {
return;
}
return client;
}
async getUser(username, password) {
const user = nconf.get('user');
if (username !== user.username || password !== user.password) {
return;
}
return { userId: user.id };
}
async getAccessToken(bearerToken) {
const token = nconf.get('token');
token.accessTokenExpiresAt = new Date(token.accessTokenExpiresAt);
token.refreshTokenExpiresAt = new Date(token.refreshTokenExpiresAt);
const user = nconf.get('user');
const client = nconf.get('client');
token.user = user;
token.client = client;
return token;
}
async saveToken(token, client, user) {
const _token = Object.assign({}, token, { user }, { client });
nconf.set('token', _token);
nconf.save();
return _token;
}
}
return Model;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codingchengdu/egg-oauth2-server.git
git@gitee.com:codingchengdu/egg-oauth2-server.git
codingchengdu
egg-oauth2-server
egg-oauth2-server
master

搜索帮助