1

我已经搜索并找到了一些东西,但这里没有完整的文档。

有人可以给我一步一步的解释吗?

我已经配置好 IdentityServer3 并且我确认我可以通过浏览器访问 IdentityManager 并完美地管理用户。现在,我需要从另一个定制的应用程序管理用户。所以我需要:

  1. 通过自定义应用程序登录

  2. 通过 Idm API 管理用户。

我已经使用“ResourceOwner”授权并使用“idmgr”范围来获取访问令牌:https://localhost:44376/ids/connect/token.

但是当我使用该令牌访问https://localhost:44376/idm/api/users?count=10&start=0时,我收到了消息"Authorization has been denied for this request."

4

1 回答 1

0
        var client = new HttpClient();
        var dic = new Dictionary<string, string>();
        dic.Add("client_id", "mvc");
        dic.Add("client_secret", "secret");
        dic.Add("grant_type", "password");
        dic.Add("scope", "openid profile");
        dic.Add("username", "yazan@catec.ae");
        dic.Add("password", "P@ssword1");

        var content = new FormUrlEncodedContent(dic);

        var msg = client.PostAsync("https://localhost:44383/identity/connect/token", content).Result.Content.ReadAsStringAsync().Result;
        string token = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(msg).access_token;

        var jwt = new JwtSecurityToken(token);
        var identity = new ClaimsIdentity("ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
        foreach (var c in jwt.Claims)
        {
            var t = c.Type;
            var v = c.Value;

            identity.AddClaim(new Claim(t, v));

        }
            IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication;
            authenticationManager.SignOut("ApplicationCookie");
            authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);

        return Redirect("Index");
于 2016-12-10T01:48:47.130 回答