| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- const Response = require('../util/response');
- class AuthController{
- static checkClient(ctx){
- const allowed_client_ids = ['seec-portal'];
- const allowed_redirect_domains = ['localhost:3000', 'localhost:8000'];
- const query = ctx.query;
- console.log('query', query);
- const {client_id, redirect_uri, scope} = query;
- if(!client_id || !redirect_uri || !scope){
- ctx.body=Response.failed("非法请求,拒绝访问");
- }
- else if(allowed_client_ids.indexOf(client_id) < 0 || scope !== "openid" || (redirect_uri.indexOf('https://')!==0 && redirect_uri.indexOf('http://')!==0) ){
- ctx.body=Response.failed("非法请求,拒绝访问");
- }
- else{
- let durl=/http:\/\/([^\/]+)\//i;
- let domain = redirect_uri.match(durl)[1];
- // console.log('domain',domain);
- if(allowed_redirect_domains.indexOf(domain) < 0){
- ctx.body=Response.failed("非法请求,拒绝访问");
- }else{
- ctx.cookies.set('redirect_uri', redirect_uri, {
- maxAge:60*1000*3
- });
- ctx.cookies.set('client_id', client_id, {
- maxAge:60*1000*3
- });
- ctx.redirect("/login");
- }
- }
- }
- }
- module.exports = AuthController;
|