简体   繁体   English

如何在 VSCode 扩展中使用 openid 登录?

[英]How to login using openid in VSCode extension?

I need some inputs/suggestions on how to login into VSC extension.我需要一些关于如何登录 VSC 扩展的输入/建议。 I have already done similar stuff for web application in angular using https://www.npmjs.com/package/angular-auth-oidc-client library.我已经使用https://www.npmjs.com/package/angular-auth-oidc-client库为 angular 中的 web 应用程序做了类似的事情。

I am developing VSC extension(typescript language) in which I have to authenticate users before they use it.我正在开发 VSC 扩展(打字稿语言),我必须在用户使用之前对其进行身份验证。 For that, I have cloudIDP auth URL to which I have to forward the request for users to get logged in first.为此,我有 cloudIDP 身份验证 URL,我必须将请求转发到该 URL,以便用户首先登录。 Once user is logged in, Users should come back to VSC extension and then start using in-built extension commands.用户登录后,用户应返回 VSC 扩展,然后开始使用内置扩展命令。

I am using https://www.npmjs.com/package/openid-client library with code flow.我正在使用带有代码流的https://www.npmjs.com/package/openid-client库。 I am able to open login url, getting users loggedin, coming back to vscode extension but without token.我能够打开登录 url,让用户登录,回到 vscode 扩展但没有令牌。

let req = Client.authorizationUrl({
    client_id: 'CLIENT:ID',
    client_secret: 'CLIENT_SECRET',
    redirect_uri: 'vscode://EXTENSION_NAME/auth',
    scope: 'openid profile email offline_access',
    response_type: ['code'],
    code_challenge,
    code_challenge_method: 'S256',
});

//This opens browser window from vscode and user gets logged in and comes back to extension
vscode.env.openExternal(vscode.Uri.parse(req)).then((response) => {
    console.log('Signin response: ', response); // returns true
    // not sure how to proceed here
});

Is my approach right or do I need to do anything else here ?我的方法是正确的还是我需要在这里做任何其他事情?

Please guide me, Thanks in advance.请指导我,提前致谢。

Alpesh阿尔佩什

I got it working.我让它工作了。

After redirection, I have to handle logic in UriHandler class and then hitting the api for getting token there with the code params as received in after redirection.重定向后,我必须处理 UriHandler 类中的逻辑,然后使用重定向后收到的代码参数访问 api 以获取令牌。

Let me know if you want to understand (or in future), I would love to guide there.如果您想了解(或将来),请告诉我,我很乐意为您提供指导。

Regards, Alpesh问候, 阿尔佩什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM