oauth2-mock-server发送配置文件ID

发布于 2025-02-11 08:38:58 字数 1747 浏览 0 评论 0原文

我正在尝试测试OAuth2护照设置,并找到了此软件包。 https://www.npmjs.coms.com/package/package/oauth2-mock-server/oauth2-mock-server 我正在尝试使用它返回配置文件对象,但没有成功。

有人使用过这个包装吗? 我将如何传递一个配置文件对象?

我的模拟设置:

    const { OAuth2Server } = require("oauth2-mock-server");
    const request = require("request");
    
    async function startServer() {
      let server = new OAuth2Server();
      await server.issuer.keys.generate("RS256");
      await server.start(3003, "localhost");
    
      server.service.once("beforeResponse", (tokenEndpointResponse, req) => {
        console.log("tokenEndpointResponse = ", tokenEndpointResponse);
        tokenEndpointResponse.body = {
          ...tokenEndpointResponse.body,
          scope: { profile: { id: "xxx" } },
        };
      });
    
      server.service.once(
        "beforeAuthorizeRedirect",
        (authorizeRedirectUri, req) => {
          console.log("THIS WAS TRIGGERED >>>> = ", authorizeRedirectUri);
        }
      );
    }
startServer();

我的oauth2strategy

const strategy = new OAuth2Strategy(
  {
    state: true,
    authorizationURL: `${process.env.MOCK_AUTH_SERVER_URL}/authorize`,
    tokenURL: `${process.env.MOCK_AUTH_SERVER_URL}/token`,
    clientID: "xxx",
    clientSecret: "xxx",
    callbackURL: `${process.env.SERVER_URL}/callback`,
    passReqToCallback: true,
  },
  async (accessToken, refershToken, profile, done) => {
    console.log("profile = ", profile);
    if (profile) {
      return done(null, profile);
    }
}
);

我不断恢复个人资料字符串,但想要配置文件对象?

I'm trying to test a OAuth2 passport setup and I found this package.
https://www.npmjs.com/package/oauth2-mock-server
I'm trying to return a profile object using it but with no success.

Has anyone used this package ?
How would I pass back a profile object ?

My mock setup:

    const { OAuth2Server } = require("oauth2-mock-server");
    const request = require("request");
    
    async function startServer() {
      let server = new OAuth2Server();
      await server.issuer.keys.generate("RS256");
      await server.start(3003, "localhost");
    
      server.service.once("beforeResponse", (tokenEndpointResponse, req) => {
        console.log("tokenEndpointResponse = ", tokenEndpointResponse);
        tokenEndpointResponse.body = {
          ...tokenEndpointResponse.body,
          scope: { profile: { id: "xxx" } },
        };
      });
    
      server.service.once(
        "beforeAuthorizeRedirect",
        (authorizeRedirectUri, req) => {
          console.log("THIS WAS TRIGGERED >>>> = ", authorizeRedirectUri);
        }
      );
    }
startServer();

My OAuth2Strategy

const strategy = new OAuth2Strategy(
  {
    state: true,
    authorizationURL: `${process.env.MOCK_AUTH_SERVER_URL}/authorize`,
    tokenURL: `${process.env.MOCK_AUTH_SERVER_URL}/token`,
    clientID: "xxx",
    clientSecret: "xxx",
    callbackURL: `${process.env.SERVER_URL}/callback`,
    passReqToCallback: true,
  },
  async (accessToken, refershToken, profile, done) => {
    console.log("profile = ", profile);
    if (profile) {
      return done(null, profile);
    }
}
);

I keep getting back a string for profile but wanted the profile object ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文