fusionauth 通用sso 解决方案学习二 基本试用

前边有简单的关于fusionauth的环境搭建,以下是关于fusionauth使用的说明

环境搭建

参考https://www.cnblogs.com/rongfengliang/p/12777247.html

配置

  • 创建app


  • 集成url

 
extends layout
block content
  h1= title
  if user
    p Hello #{user.firstName}
  else
    a(href='http://localhost:9011/oauth2/authorize?client_id=9822f717-6a43-419a-a2f1-764100a3f50f&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth-redirect') Login
  p Welcome to #{title}
 
  • 配置用户权限
  • 添加路由
    /oauth-redirect
    代码:
 
const express = require('express');
const router = express.Router();
const {FusionAuthClient} = require('@fusionauth/node-client');
const client = new FusionAuthClient('9822f717-6a43-419a-a2f1-764100a3f50f', 'http://localhost:9011');
/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', {user: req.session.user, title: 'FusionAuth Example'});
});
/* OAuth return from FusionAuth */
router.get('/oauth-redirect', function (req, res, next) {
  // This code stores the user in a server-side session
  client.exchangeOAuthCodeForAccessToken(req.query.code,
                                         '9822f717-6a43-419a-a2f1-764100a3f50f',
                                         'Hx7mEG8oXJ-NwjiAqMNBpXUKy-Xtf_t8hbNub9DGHGw',
                                         'http://localhost:3000/oauth-redirect')
      .then((response) => {
        return client.retrieveUserUsingJWT(response.successResponse.access_token);
      })
      .then((response) => {
        req.session.user = response.successResponse.user;
      })
      .then(() => {
        res.redirect(302, '/');
      });
});
module.exports = router;
  • 效果


登录


效果


cache

说明

以上是一个简单的集成试用,fusionauth 同时也支持比较强大的主题管理,这点也是比较灵活的,可以自定义配置不同应用的界面(当然也是挺费事的)
参考截图


参考修改登录界面

参考资料

https://fusionauth.io/docs/v1/tech/5-minute-setup-guide
https://github.com/rongfengliang/fusionauth-node-example
https://github.com/FusionAuth/fusionauth-localization

原文地址:https://www.cnblogs.com/rongfengliang/p/12779650.html