在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/userauth开源软件地址:https://github.com/koajs/userauth开源编程语言:JavaScript 96.8%开源软件介绍:koa-userauth
Install$ npm install koa-userauth Usage
var koa = require('koa');
var userauth = require('koa-userauth');
var session = require('koa-generic-session');
var app = new koa();
app.keys = ['i m secret'];
app.use(session());
app.use(userauth({
match: '/user',
// auth system login url
loginURLFormatter: function (url) {
return 'http://login.demo.com/login?redirect=' + url;
},
// login callback and getUser info handler
getUser: async ctx => {
var token = this.query.token;
// get user
return user;
}
})); ArgumentsIf /**
* User auth middleware.
*
* @param {Object} [options]
* - {String|Regex|Function(pathname, ctx)} match, detect which url need to check user auth.
* `''` empty string meaning match all, @see `path-match` package.
* - {String|Regex|Function(pathname, ctx)} ignore, detect which url no need to check user auth.
* If `match` exists, this argument will be ignored.
* - {Function(url, rootPath, ctx)} loginURLFormatter, format the login url.
* - {String} [rootPath], custom app url root path, default is '/'.
* - {String} [loginPath], default is '/login'.
* - {String} [loginCallbackPath], default is `options.loginPath + '/callback'`.
* - {String} [logoutPath], default is '/logout'.
* - {String} [userField], logined user field name on `this.session`, default is 'user', `this.session.user`.
* - {Async Function (ctx)} getUser, get user function, must get user info with `req`.
* - {Async Function (ctx, user)} [loginCallback], you can handle user login logic here,return [user, redirectUrl]
* - {Function(ctx)} [loginCheck], return true meaning logined. default is `true`.
* - {Async Function (ctx, user)} [logoutCallback], you can handle user logout logic here.return redirectUrl
* - {Function(ctx)} [getRedirectTarget], customize how to get the redirect target after login
* @return {Async Function (next)} userauth middleware
* @public
*/ Login flow
License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论