Exemplo n.º 1
0
        public async Task <HttpResponseMessage> MakeRequestAsync(
            IOidcSettingsConfidentialClientConfiguration oidcSettingsConfidentialClientConfiguration,
            string authorityUriOverride, HttpContextBase httpContextBase, string[] fqScopes, HttpMethod verb,
            Uri apiUri)
        {
            var httpRequestMessage = new HttpRequestMessage(verb, apiUri);

            return(await MakeRequestAsync(oidcSettingsConfidentialClientConfiguration, authorityUriOverride, httpContextBase,
                                          fqScopes,
                                          httpRequestMessage));
        }
        public Task <HttpResponseMessage> MakeRequestAsync(
            IOidcSettingsConfidentialClientConfiguration oidcSettingsConfidentialClientConfiguration,
            string authorityUriOverride,
            HttpContextBase httpContextBase,
            string[] fqScopes,
            HttpRequestMessage httpRequestMessage)
        {
            var oidcRequestHelper = new OidcRequestHelper(this._diagnosticsTracingService);

            return(oidcRequestHelper.MakeRequestAsync(
                       oidcSettingsConfidentialClientConfiguration,
                       authorityUriOverride,
                       httpContextBase,
                       fqScopes,
                       httpRequestMessage
                       ));
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> MakeRequestAsync(
            IOidcSettingsConfidentialClientConfiguration oidcSettingsConfidentialClientConfiguration, string authorityUriOverride,
            HttpContextBase httpContextBase, string[] fqScopes, HttpRequestMessage httpRequestMessage)
        {
            var authorityUri = authorityUriOverride ?? oidcSettingsConfidentialClientConfiguration.AuthorityUri;

            var confidentialClientApplication =
                CreateConfidentialClientApplication(httpContextBase, authorityUriOverride,
                                                    oidcSettingsConfidentialClientConfiguration);

            var accessToken = await AcquireTokenSilently(confidentialClientApplication, authorityUri, fqScopes);

            var client = new HttpClient();

            AttachBearerToken(httpRequestMessage, accessToken);

            var response = await client.SendAsync(httpRequestMessage);

            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     A helper method to create a ConfidentialClientApplication
        ///     required to retrieve the token that is needed to be attached
        ///     as a Bearer Token to a Request.
        ///     <para>
        ///         This code is for an AAD (it's using AuthenticationUri, rather than .AuthorityCookieConfigurationPolicyUri)
        ///     </para>
        /// </summary>
        public ConfidentialClientApplication CreateConfidentialClientApplication(
            HttpContextBase httpContextBase,
            string authorityUriOverride,
            IOidcSettingsConfidentialClientConfiguration oidcSettingsConfidentialClientConfiguration,
            params string[] fqScopes)
        {
            // ** IMPORTANT**
            // The calls to AAD and B2C are mostly the same bar the following:
            // For AAD, use .AuthorityUri
            var        authorityUri           = authorityUriOverride ?? oidcSettingsConfidentialClientConfiguration.AuthorityUri;
            var        signedInUserIdentifier = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            var        userTokenCache         = new MSALSessionCache(signedInUserIdentifier, httpContextBase).GetMsalCacheInstance();
            TokenCache appTokenCache          = null;

            var confidentialClientApplication = new ConfidentialClientApplication(
                oidcSettingsConfidentialClientConfiguration.ClientId,
                authorityUri /*note...*/,
                oidcSettingsConfidentialClientConfiguration.ClientRedirectUri,
                new ClientCredential(oidcSettingsConfidentialClientConfiguration.ClientSecret),
                userTokenCache,
                appTokenCache);

            return(confidentialClientApplication);
        }