Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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# Azure Mobile Services自定义LoginProvider使用AuthenticationHandler在通用应用程序中重定向问题_C#_Oauth 2.0_Azure Mobile Services_Win Universal App_Owin Middleware - Fatal编程技术网

C# Azure Mobile Services自定义LoginProvider使用AuthenticationHandler在通用应用程序中重定向问题

C# Azure Mobile Services自定义LoginProvider使用AuthenticationHandler在通用应用程序中重定向问题,c#,oauth-2.0,azure-mobile-services,win-universal-app,owin-middleware,C#,Oauth 2.0,Azure Mobile Services,Win Universal App,Owin Middleware,问题是: MobileServiceClient.LoginAsync永远不会退出登录对话框-即使在返回访问令牌之后 环境: 后端:Windows Azure移动服务.Net/C 前端:Windows 8.1通用商店应用程序。净额/C 详情如下: 在我的应用程序中,以下代码无法从第二行显示的对话框中返回: var client = new MobileServiceClient("https://hana.azure-mobile.net", applicationKey); var resul

问题是:

MobileServiceClient.LoginAsync永远不会退出登录对话框-即使在返回访问令牌之后

环境:

后端:Windows Azure移动服务.Net/C 前端:Windows 8.1通用商店应用程序。净额/C 详情如下:

在我的应用程序中,以下代码无法从第二行显示的对话框中返回:

var client = new MobileServiceClient("https://hana.azure-mobile.net", applicationKey);
var result = await client.LoginAsync("SmartThings");
猜测:

我怀疑我的自定义AuthenticationHandler中用于处理质询的代码是主要原因。ApplyResponseChallengeAsync重写的AuthenticationProperties中的重定向uri始终为空-因此它将重定向uri设置为请求uri

代码如下所示:

        var redirectUri = Request.FromPath(Options.CallbackPath);
        var properties = challenge.Properties;

        if (String.IsNullOrEmpty(properties.RedirectUri))
        {
            properties.RedirectUri = Request.Uri.AbsoluteUri;
        }

        // OAuth2 10.12 CSRF
        GenerateCorrelationId(properties);

        var requestUrl = FormAuthorizeRequest(properties, redirectUri);
        Response.Redirect(requestUrl);
试图解决问题

使用WebAuthenticationBroker而不是MobileServiceClient,并明确提供回调uri。 删除重定向uri的重新分配。 切换重定向和请求URI。 把盐扔到我肩上。 使用服务上的测试前端导航和测试登录。 使用HttpClient并使用以下参数键显式构造请求:redirect_uri、redirect_url、redirectUrl、redirectUri。 使山羊流血 将AuthenticationOptions的CallbackPath值更改为/signin SmartThings。 等待拉格纳罗 其他细节

我必须创建一个自定义LoginProvider和OWIN中间件,以便将自定义AuthenticationHandler注册到OWIN管道中。这似乎是正确设置的,但我的AuthenticationHandler的实现可能是错误的。如果有助于加快这一问题的解决,我将很乐意根据要求提供更多细节

更新:

当尝试使用提供的回调uri从WebAuthenticationBroker登录时,来自SmartThings的响应在正文中给出了重定向不匹配的错误

但是,在浏览器中导航时,重定向uri会按如下方式处理:


这让我有点困惑,因为我希望看到一个访问令牌,而不是身份验证令牌,作为重定向uri。

问题出在电话端,还是Windows应用商店端,还是两者都有?我还没有使用Windows phone项目。现在,我只使用适用于Windows 8.1的通用Windows应用商店应用程序。我怀疑Azure移动服务的问题比WebAuthenticationBroker更大。但这纯粹是猜测。调试器的输出窗口中是否有任何内容?不确定移动服务是否了解SmartThings提供商。我为SmartThings创建了一个自定义的LoginProvider/中间件。在我的问题中发布了可能出错的Owin中间件的代码。但是,如果您需要管道中的任何其他代码,我很乐意提供它。另外,正如您所知,端点是可公开访问的,您可以通过端点导航来实际验证和授权身份。问题似乎是返回上下文上的重定向url格式不正确-这意味着WebAuthenticationBroker不知道如何响应重定向。