示例#1
0
        public async Task <IActionResult> ObapiViaHybridConnection(string scheme = "https")
        {
            var           obapiDomain  = "devtest-obapi.vfltest.dk";
            var           adfsDomain   = "devtest-idp.vfltest.dk";
            WsTrustClient c            = new WsTrustClient(adfsDomain);
            var           tokenRequest = new SamlTokenRequest
            {
                Audience = $"https://{obapiDomain}/",
                Username = _configuration["serviceusername"],
                Password = _configuration["servicepassword"],
            };
            var tokenResponse = await c.RequestTokenAsync(tokenRequest);

            var encodedToken = new DeflatedSamlEncoder().Encode(tokenResponse.TokenXml);

            using var client = _httpClientFactory.CreateClient();
            var request = new HttpRequestMessage(HttpMethod.Get, $"{scheme}://{obapiDomain}/v2/Users/");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", encodedToken);
            var response = await client.SendAsync(request);

            var responseContent = await response.Content.ReadAsStringAsync();

            var output =
                $"User: {tokenRequest.Username}{Environment.NewLine}Request url: {request.RequestUri}{Environment.NewLine}StatusCode: {response.StatusCode}{Environment.NewLine}Content:{Environment.NewLine}{responseContent}";

            return(this.Content(output));
        }
示例#2
0
        public void CanRequestToken()
        {
            var client  = new global::Seges.IdentityModel.WsTrust.WsTrustClient("si-idp.vfltest.dk");
            var request = new SamlTokenRequest
            {
                Audience = "https://devtest-www-landmanddk.vfltest.dk",
                Username = "******",
                Password = "******"
            };
            var token = client.RequestTokenAsync(request).Result;

            Assert.IsNotNull(token);
            Assert.IsTrue(token.TokenXml.StartsWith("<saml:Assertion"));
        }