示例#1
0
        public async Task <ActionResult> RequestToken([FromBody] RequestTokenParam model)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict["client_id"]     = configuration["IdentityService:ClientId"];
            dict["client_secret"] = configuration["IdentityService:ClientSecret"];
            dict["grant_type"]    = configuration["IdentityService:GrantType"];
            dict["username"]      = model.UserName;
            dict["password"]      = model.Password;

            using (HttpClient http = new HttpClient())
                using (var content = new FormUrlEncodedContent(dict))
                {
                    var msg = await http.PostAsync(configuration["IdentityService:TokenUri"], content);

                    if (!msg.IsSuccessStatusCode)
                    {
                        return(StatusCode(Convert.ToInt32(msg.StatusCode)));
                    }

                    string result = await msg.Content.ReadAsStringAsync();

                    return(Content(result, "application/json"));
                }
        }
示例#2
0
 public async Task<ActionResult> RequestToken(RequestTokenParam model)
 {
     Dictionary<string, string> dict = new Dictionary<string, string>();
     //秘钥存在这个服务器上,请求这台服务器然后转发
     dict["client_id"] = "clientPC1";
     dict["client_secret"] = "123321";
     dict["grant_type"] = "password";
     dict["username"] = model.username;
     dict["password"] = model.password;
     //由登录服务器向IdentityServer发请求获取Token
     using (HttpClient http = new HttpClient())
     using (var content = new FormUrlEncodedContent(dict))
     {
         var msg = await http.PostAsync("http://localhost:9500/connect/token", content);
         string result = await msg.Content.ReadAsStringAsync();
         return Content(result, "application/json");
     }
 }