示例#1
0
        public async Task <IActionResult> GetV2AuthCodeAsync()
        {
            TokenTool.Microsoft.v2.AccessToken accessToken;
            TokenTool.Microsoft.v2.AccessToken refreshedToken;

            var queryString = this.Request.QueryString.ToString();

            var authorizationCodeGrant = new TokenTool.Microsoft.v2.AuthorizationCodeGrant()
            {
                ClientId     = config["v2Endpoint:clientId"],
                ClientSecret = config["v2Endpoint:clientSecret"],
                Scope        = config["v2Endpoint:scopes"],
                RedirectUri  = "http://localhost:64191/auth/authcode"
            };

            using (HttpClient httpClient = new HttpClient())
            {
                accessToken = await authorizationCodeGrant.ProcessAuthorizationResponse(queryString);

                refreshedToken = await authorizationCodeGrant.RefreshAccessToken(accessToken);
            }

            var idToken = TokenTool.Microsoft.IDToken.Parse(accessToken.IdToken);

            return(new JsonResult(new { accessToken, refreshedToken, idToken },
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
            }));
        }
示例#2
0
        private void Setupv2()
        {
            var adminConsentGrant = new TokenTool.Microsoft.v2.AdminConsentGrant(config["v2Endpoint:clientId"], "http://localhost:64191/auth/admin");

            V2AdminUri = adminConsentGrant.AuthorizationUri;

            var authorizationCodeGrant = new TokenTool.Microsoft.v2.AuthorizationCodeGrant()
            {
                ClientId    = config["v2Endpoint:clientId"],
                Scope       = config["v2Endpoint:scopes"],
                RedirectUri = "http://localhost:64191/auth/authcode",
                Prompt      = "consent"
            };

            V2AuthUri = authorizationCodeGrant.AuthorizationUri;

            var implicitGrant = new TokenTool.Microsoft.v2.ImplicitGrant()
            {
                ClientId    = config["v2Endpoint:clientId"],
                RedirectUri = "http://localhost:64191/",
                Scope       = "user.read",
                Prompt      = "consent"
            };

            V2ImplicitUri = implicitGrant.AuthorizationUri;

            var openIdImplicitGrant = new TokenTool.Microsoft.v2.ImplicitGrant()
            {
                ClientId     = config["v2Endpoint:clientId"],
                RedirectUri  = "http://localhost:64191/auth/implicit",
                ResponseType = "id_token+token",
                Scope        = "openid email profile user.read",
                Prompt       = "consent"
            };

            V2OpenIdUri = openIdImplicitGrant.AuthorizationUri;
        }