Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASMX(web参考)中实现OAuth 2.0?_C#_Wcf_Xamarin_Oauth 2.0_Asmx - Fatal编程技术网

C# 如何在ASMX(web参考)中实现OAuth 2.0?

C# 如何在ASMX(web参考)中实现OAuth 2.0?,c#,wcf,xamarin,oauth-2.0,asmx,C#,Wcf,Xamarin,Oauth 2.0,Asmx,我对实现OAuth2.0非常陌生。我已经在我的xamarin项目中实现了web引用(ASMX文件)。现在我需要实现OAuth2.0进行身份验证。但是我不确定ASMX是否支持OAuth2.0。我是否需要实现WCF而不是Web引用(ASMX),或者是否可以在Web引用(ASMX)中实现OAuth2.0?一个可能的解决方案是将从授权机构获得的令牌添加到授权标头。 您的代码可能与此类似: var redirectURI = Windows.Security.Authentication.Web.WebA

我对实现OAuth2.0非常陌生。我已经在我的xamarin项目中实现了web引用(ASMX文件)。现在我需要实现OAuth2.0进行身份验证。但是我不确定ASMX是否支持OAuth2.0。我是否需要实现WCF而不是Web引用(ASMX),或者是否可以在Web引用(ASMX)中实现OAuth2.0?

一个可能的解决方案是将从授权机构获得的令牌添加到授权标头。 您的代码可能与此类似:

var redirectURI = Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
var _authContext = new AuthenticationContext(authority);
var tokenResult = await _authContext.AcquireTokenAsync(serviceResourceId, clientId, redirectURI);
if (tokenResult.Status != AuthenticationStatus.Success)
{
    //Not authenticated
    return;
}
var svc = new YourServiceReference.YourClient();
using (var scope = new OperationContextScope(svc.InnerChannel))
{
    var httpRequestProperty = new HttpRequestMessageProperty();
    httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = tokenResult.AccessToken;
    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
    var result = svc.MyFunction();
    //Do something with the data
}

棘手-这是移动OAuth解决方案的工作方式-但这是一项艰巨的工作:

  • 您的Xamarin应用程序需要实现移动SSO才能让用户登录
  • Xamarin应用程序的用户将被重定向到通过授权服务器/身份提供商登录,之后他们将收到OAuth访问令牌
  • 登录后,您的Xamarin应用程序将能够使用令牌调用API,并代表用户获取数据
  • API需要验证收到的访问令牌
解决方案部件

API:ASMX是一项古老的技术,因此如果您使用的是Microsoft堆栈,您将使用更新的技术,例如.Net核心Web API

移动应用程序:解决方案中较难的部分将是实施移动SSO,如果您还没有这样做的话

这个解决方案已经存在多少