The Problem:

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

The Environment:

  • Backend: Windows Azure移动服务.Net / C#

  • Frontend: Windows 8.1 Universal Store App . .NET / C#

The Details:

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

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

Speculation:

我怀疑我的自定义AuthenticationHandler中用于处理挑战的代码主要是责备 . 我重写ApplyResponseChallengeAsync的AuthenticationProperties中的RedirectUri始终为null - 因此它将重定向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);

Attempts at resolution

  • 使用WebAuthenticationBroker而不是MobileServiceClient,并且expliticly提供回调uri .

  • 删除重新分配以重定向uri .

  • 切换重定向并请求uris .

  • 在我的肩膀上撒盐 .

  • 使用服务上的测试前端来导航和测试登录 .

  • 使用HttpClient并使用以下参数键显式构造请求:"redirect_uri","redirect_url","redirectUrl","redirectUri" .

  • 流血了一只山羊

  • 将AuthenticationOptions的CallbackPath值更改为"/signin-SmartThings" .

  • 等待Ragnarok

Additional Details

我必须创建一个自定义LoginProvider和OWIN Middleware来将我的自定义AuthenticationHandler注册到owin管道中 . 这似乎已正确设置,但我的AuthenticationHandler的实现可能是错误的 . 如果有助于加快解决这个问题,我很乐意提供其他详细信息 .

Updates:

当尝试使用提供的回调uri从WebAuthenticationBroker登录时,SmartThings的响应在主体中出现“redirect_mismatch”错误 .

但是,在浏览器中导航时,重定向uri会被处理为“https://hana.azure-mobile.net/signin-SmartThings?code=somemassivecode

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