auth.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const Response = require('../util/response');
  2. class AuthController{
  3. static checkClient(ctx){
  4. const allowed_client_ids = ['seec-portal'];
  5. const allowed_redirect_domains = ['localhost:3000', 'localhost:8000'];
  6. const query = ctx.query;
  7. console.log('query', query);
  8. const {client_id, redirect_uri, scope} = query;
  9. if(!client_id || !redirect_uri || !scope){
  10. ctx.body=Response.failed("非法请求,拒绝访问");
  11. }
  12. else if(allowed_client_ids.indexOf(client_id) < 0 || scope !== "openid" || (redirect_uri.indexOf('https://')!==0 && redirect_uri.indexOf('http://')!==0) ){
  13. ctx.body=Response.failed("非法请求,拒绝访问");
  14. }
  15. else{
  16. let durl=/http:\/\/([^\/]+)\//i;
  17. let domain = redirect_uri.match(durl)[1];
  18. // console.log('domain',domain);
  19. if(allowed_redirect_domains.indexOf(domain) < 0){
  20. ctx.body=Response.failed("非法请求,拒绝访问");
  21. }else{
  22. ctx.cookies.set('redirect_uri', redirect_uri, {
  23. maxAge:60*1000*3
  24. });
  25. ctx.cookies.set('client_id', client_id, {
  26. maxAge:60*1000*3
  27. });
  28. ctx.redirect("/login");
  29. }
  30. }
  31. }
  32. }
  33. module.exports = AuthController;