Esempio n. 1
0
        async Task<string> CallWebAPI(bool callTest2)
        {
            var adfsIntegrationUrl = "https://sso.altegrity.com/issue/adfs";
            var webAPIId = "http://localhost/rp-adfs-webapi";
            var webAPIService = "https://localhost/rp-adfs-webapi/api/test1";

            // call adfs integration to convert saml to jwt for webapi RP
            var adfsProxy = new AdfsIntegrationProxy(adfsIntegrationUrl);
            string jwt = null;
            // need original token to get new token
            var bootstrapCtx = ClaimsPrincipal.Current.Identities.First().BootstrapContext as BootstrapContext;
            if (bootstrapCtx.SecurityToken != null)
            {
                jwt = await adfsProxy.SamlToJwtAsync(bootstrapCtx.SecurityToken, webAPIId);
            }
            else if (bootstrapCtx.Token != null)
            {
                jwt = await adfsProxy.SamlToJwtAsync(bootstrapCtx.Token, webAPIId);
            }
            else
            {
                throw new Exception("No bootstrap context token available");
            }

            // call webapi RP with jwt
            var client = new HttpClient { BaseAddress = new Uri(webAPIService) };
            client.DefaultRequestHeaders.Authorization =
                new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", jwt);

            var response = await client.GetAsync("?callTest2=" + callTest2.ToString());
            response.EnsureSuccessStatusCode();

            var json = await response.Content.ReadAsStringAsync();
            return json;
        }
        private async Task<object> CallTest2(bool callTest2)
        {
            if (callTest2 == false) return null;

            var adfsIntegrationUrl = "https://idsrv.local/issue/adfs";
            var webAPIId = "http://localhost/rp-adfs-webapi2";
            var webAPIService = "https://localhost/rp-adfs-webapi/api/test2";

            // call adfs integration to convert saml to jwt for webapi RP
            var adfsProxy = new AdfsIntegrationProxy(adfsIntegrationUrl);
            var token = Request.Headers.Authorization.Parameter;
            var jwt = await adfsProxy.JwtToJwtAsync(token, webAPIId);

            // call webapi RP with jwt
            var client = new HttpClient { BaseAddress = new Uri(webAPIService) };
            client.DefaultRequestHeaders.Authorization =
                new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", jwt);

            var response = await client.GetAsync("");
            response.EnsureSuccessStatusCode();

            var json = await response.Content.ReadAsStringAsync();
            return JArray.Parse(json);
        }