【问题标题】:DotNetOpenAuth Oauth 2, what to do with code response?DotNetOpenAuth Oauth 2,如何处理代码响应?
【发布时间】:2015-11-10 12:24:53
【问题描述】:

我正在为我们的 Web 应用程序中的用户授权 LinkedIn 应用程序。在基础上,它在 .NET 4.5.2 上使用带有 .NET Web api 后端的 angularjs。

在回调之前我确实让它工作了。代码如下:

public string GetAuthenticationUrl(string context, string redirectUrl)
{
        if(context == null)
            throw new ArgumentException(nameof(context));
        if (string.IsNullOrEmpty(redirectUrl))
            throw new ArgumentException(nameof(redirectUrl));

        var appContext = _applicationContextProvider.GetLinkedInApplicationContext();
        var linkedIn = new UserAgentClient(new AuthorizationServerDescription
        {
            TokenEndpoint = new Uri(appContext.AccessTokenEndpoint),
            AuthorizationEndpoint = new Uri(appContext.AuthorizationEndpoint),
            ProtocolVersion = ProtocolVersion.V20
        }, appContext.ClientId, appContext.ClientSecret);

        var target = linkedIn.RequestUserAuthorization(null, context, new Uri(redirectUrl));

        return target.AbsoluteUri;
    }

它返回一个我可以用来访问 LinkedIn 的 Url。 我授权应用程序并成功重定向到我的 redirectUrl,我在其中获得代码和状态。

但是接下来我该怎么做才能请求访问令牌?

public void Confirm(string state, string code)
{
// ?
}

我使用 dotnetopenauth 4.3

最好的问候 乔纳斯

【问题讨论】:

    标签: oauth-2.0 linkedin dotnetopenauth


    【解决方案1】:

    我想通了。所以对于未来的冒险者:

    public void Confirm(string context, string code)
        {
            if (context == null)
                throw new ArgumentException(nameof(context));
            if (string.IsNullOrEmpty(code))
                throw new ArgumentException(nameof(code));
    
            var appContext = _applicationContextProvider.GetLinkedInApplicationContext();
            var linkedIn = new UserAgentClient(new AuthorizationServerDescription
            {
                TokenEndpoint = new Uri(appContext.AccessTokenEndpoint),
                AuthorizationEndpoint = new Uri(appContext.AuthorizationEndpoint),
                ProtocolVersion = ProtocolVersion.V20
            }, appContext.ClientId, appContext.ClientSecret)
            {
                ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(appContext.ClientSecret)
            };
    
            var auth = linkedIn.ProcessUserAuthorization(new Uri($"http://fake.url?code={code}"), new AuthorizationState
            {
                Callback = new Uri("<addd original return_url here from code request>")
            });
        }
    

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 2015-08-11
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多