修改 app.js
// app.js
const Koa = require('koa');
const { PORT = 3000 } = process.env;
const app = new Koa();
let server;
(async () => {
let adapter;
server = app.listen(PORT, () => {
console.log(`application is listening on port ${PORT}`);
});
})().catch((err) => {
if (server && server.listening) server.close();
console.error(err);
process.exitCode = 1;
});
测试执行
npm run dev
成功显示
PS D:\projects\joy-sso> npm run dev
> joy-sso@1.0.0 dev
> node app.js
application is listening on port 3000.
修改 app.js,引入OIDC,并创建 Provider。
// app.js
...
const { Provider } = require('oidc-provider');
...
const ISSUER = `http://localhost:${PORT}`;
const provider = new Provider(ISSUER, {});
配置 Provider 到 KOA
// app.js
...
const mount = require('koa-mount');
...
app.use(mount(provider.app));
server = app.listen(PORT, () => {
...
测试执行
npm run dev
成功显示
PS D:\projects\joy-sso> npm run dev
> joy-sso@1.0.0 dev
> node app.js
oidc-provider WARNING: a quick start development-only in-memory adapter is used, you MUST change it in order to not lose all stateful provider data upon restart and to be able to share these between processes
application is listening on port 3000.
到这一步,OIDC 服务就已经创建好了,我们拥有了一个极简的 OIDC 服务。
中间的警告可以忽略,意思是说数据存在内存中有风险,只适用于开发的场景。
接下来,我们通过一步步的配置,完善 OIDC 服务。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。