zoukankan      html  css  js  c++  java
  • 添加 Azure Active Directory 服务,调用方法

     引入dll :Microsoft.IdentityModel.JsonWebTokens

    1
    string url = string.Format("{0}token", ConfigurationManager.AppSettings["AAdLoginUrl"]); 2 HttpClient client = new HttpClient(); 3 var dic_Form = new Dictionary<string, string>(); 4 dic_Form.Add("client_id", ConfigurationManager.AppSettings["Client_Id"]); 5 dic_Form.Add("scope", "openid"); 6 dic_Form.Add("code", codestr); 7 dic_Form.Add("redirect_uri", ConfigurationManager.AppSettings["Redirect_Uri"]); 8 dic_Form.Add("grant_type", "authorization_code"); 9 dic_Form.Add("client_secret", ConfigurationManager.AppSettings["Client_Secret"]); 10 var content = new FormUrlEncodedContent(dic_Form); 11 var response = client.PostAsync(url, content).Result; 12 resultStr = response.Content.ReadAsStringAsync().Result; 13 if (!string.IsNullOrEmpty(resultStr)) 14 { 15 //ADDResultModel根据文档创建的返回信息实体类,需要自己根据需求创建 16 var result = JsonConvert.DeserializeObject<ADDResultModel>(resultStr); 17 if (!string.IsNullOrEmpty(result.error_description)) 18 { 19 context.Response.Write(result.error_description); 20 } 21 if (!string.IsNullOrEmpty(result.access_token)) 22 { 23 JsonWebTokenHandler handler = new JsonWebTokenHandler(); 24 if (handler.CanReadToken(result.access_token)) 25 { 26 JsonWebToken jwt = handler.ReadJsonWebToken(result.access_token); 27 var claims = jwt.Claims; 28 Claim claim1 = claims.Where(i => i.Type == "oid").FirstOrDefault(); 29 Claim claim2 = claims.Where(i => i.Type == "unique_name").FirstOrDefault(); 30 Console.WriteLine(claim1.Value); 31 Console.WriteLine(claim2.Value); 32 } 33 } 34 }
    寻寻觅觅转流年,磕磕碰碰道缘浅。 揽几缕、轻挽起,暮暮朝朝与君语。
  • 相关阅读:
    perf-stat
    perf原理
    ubuntu中Docker的安装与使用
    NVM相关手册及新特性理解
    #2018BIT软件工程基础#结对项目:四则运算题目生成
    #2018BIT软件工程基础#个人项目:数独
    第一篇博文:自我介绍&新学期展望
    越早明白这些道理,越能少走一些弯路
    把知识连接起来就是创意
    【翻译】24款界面精美的免费UI工具包
  • 原文地址:https://www.cnblogs.com/bingshao/p/14927784.html
Copyright © 2011-2022 走看看