简体   繁体   English

使用Auth令牌从C#中的服务中获取访问令牌

[英]Fetching Access token using Auth token from service in C#

I am new to the topic of Oauth and encryption. 我是Oauth和加密主题的新手。 I need to write a utility where I have authtoken with me and I need to get access token after making a call to the service url say xyzcorp.com. 我需要编写一个实用程序,在该程序中我已经过身份验证,并且在对服务网址说xyzcorp.com进行调用之后,需要获取访问令牌。 I already have auth token with me I need to use post method to make service call to the url which in turn returns access token. 我已经有了身份验证令牌,我需要使用post方法对URL进行服务调用,该URL反过来会返回访问令牌。 I couldn't find any code snippet which shows how this is done. 我找不到任何显示此操作方式的代码段。 As I already said I am a newbie into this area, don't have any clue about the implementation in c#. 正如我已经说过的,我是该领域的新手,所以对使用C#的实现一无所知。 It should be noted that I only have auth token with me. 应该注意的是,我只有身份验证令牌。

What C# library are you using? 您正在使用哪个C#库? I used Thinktecture.IdentityModel: https://github.com/thinktecture/Thinktecture.IdentityModel 我使用了Thinktecture.IdentityModel: https : //github.com/thinktecture/Thinktecture.IdentityModel

Here's an example from my OAuth2 Test Client , using IdentityModel: 这是我的OAuth2测试客户端使用IdentityModel的示例:

private static async Task<TokenResponse> SendTokenRequest(string authCode, string redirectUri)
    {
        var tokenclient = new OAuth2Client(
            new Uri(Constant.TokenEndpoint),
            Constant.CodeClientId,
            Constant.CodeClientSecret);


        return await tokenclient.RequestAuthorizationCodeAsync(authCode, redirectUri);
    }

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

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