将Xamarin客户端连接到Identity Server4

时间:2017-01-17 01:44:10

标签: xamarin oauth openid identityserver3 identityserver4

我正在尝试将本机移动应用程序(xamarin)连接到Identity Server。我最初设定流程是隐含的,我被告知它是不正确的。因此,我将其更改为授权代码流程。

以下是我的客户定义的样子

var entries =
    Directory.GetFileSystemEntries(_sourceLocation_FRUD, "*.*", SearchOption.AllDirectories)
             .Where(s => (s.StartsWith("D"))
                          && (s.Contains(".P"))
                          && (s.EndsWith(".C")));

从我的xamarin应用程序来看,这就是我连接到身份服务器的方式。

 new Client
     {
         ClientId = "Xamarin",
         ClientName = "Xamarin Client",
         AllowedGrantTypes = GrantTypes.Code,
         AllowAccessTokensViaBrowser = true,
         RedirectUris = { "http://xx.xx.xx.xx/signin-oidc" },
         PostLogoutRedirectUris = { "http://xx.xx.xx.xx/signin-oidc" },
         AllowedCorsOrigins = { "http://xx.xx.xx.xx" },
         AllowedScopes =
           {
              StandardScopes.OpenId.Name,
              StandardScopes.Profile.Name,
              "api1"
           },
         RequireConsent = false
      }

我收到了错误" unauthorized_client"在移动应用程序中,在我的服务器日志中显示:

void LoginButton_Clicked(object sender, EventArgs e)
    {
        StartFlow("token", "api1");
    }

    public void StartFlow(string responseType, string scope)
    {
        var authorizeRequest =
            new AuthorizeRequest("http://xx.xx.xx.xx/connect/authorize");


        var dic = new Dictionary<string, string>();
        dic.Add("client_id", "Xamarin");
        dic.Add("response_type", responseType);
        dic.Add("scope", scope);
        dic.Add("redirect_uri", "http://xx.xx.xx.xx/signin-oidc");
        dic.Add("nonce", Guid.NewGuid().ToString("N"));


        _currentCSRFToken = Guid.NewGuid().ToString("N");
        dic.Add("state", _currentCSRFToken);

        var authorizeUri = authorizeRequest.Create(dic);
        webLogin.Source = authorizeUri;
        webLogin.IsVisible = true;
    }

但是如果你检查我的代码我没有这个客户端类型的隐含流程。我已经仔细检查了我的数据库,以确保它是authorization_code。如果有人能帮我解决这个问题,我感激不尽。

1 个答案:

答案 0 :(得分:3)

idsrv4目前看起来不像codecode tokencode id_token token仅支持response_type - 仅code id_token。使用/authorize客户端尝试测试客户端和server.code请求时,至少当前演示站点失败。

我发现与授权代码相关的唯一有用的客户端是混合设置(code id_token / server.hybrid):

https://demo.identityserver.io/connect/authorize?
  client_id=server.hybrid&
  response_type=code id_token&
  response_mode=fragment&
  redirect_uri=https://notused&
  scope=openid api&
  state=1&
  nonce=2

不确定为什么会这样,因为它已经在发现文档的supported_response_types列表中。也许Dominic / Brock可以填写。

  "response_types_supported": [
    "code",
    "token",
    "id_token",
    "id_token token",
    "code id_token",
    "code token",
    "code id_token token"
  ],

非工作代码流验证请求(unsupported_response_type):

https://demo.identityserver.io/connect/authorize?
  client_id=server.code&
  response_type=code&
  response_mode=fragment&
  redirect_uri=https://notused&
  scope=openid api&
  state=1&
  nonce=2
相关问题