public async Task OnGetAsync() { Containers = new List <Container>(); var externalServiceEntities = await _oidcConsentOrchestratorAdmin.GetAllExternalServiceEntitiesAsync(); foreach (var es in externalServiceEntities) { var discoCache = _consentDiscoveryCacheAccessor.GetConsentDiscoveryCache(es); var doco = await discoCache.GetAsync(); Containers.Add(new Container { ExternalServiceEntity = es, ConsentDiscoveryDocumentResponse = doco }); } }
public async Task OnGetAsync() { NameIdentifier = User.Claims.GetClaimsByType(".externalNamedIdentitier").FirstOrDefault().Value; var key = _oidcPipelineKey.GetOIDCPipeLineKey(); OriginalAuthorizationRequest = await _oidcPipelineStore.GetOriginalIdTokenRequestAsync(key); var queryScopes = (from item in OriginalAuthorizationRequest.Raw where item.Key == "scope" let scopes = item.Value.Split(" ") from cItem in scopes where cItem.StartsWith(ScopeBaseUrl) select cItem).ToList(); ConsentResponseContainers = new List <ConsentResponseContainer>(); ExternalServiceEntities = await _oidcConsentOrchestratorAdmin.GetAllExternalServiceEntitiesAsync(); foreach (var es in ExternalServiceEntities) { var queryScopesService = (from item in queryScopes where item.StartsWith($"{ScopeBaseUrl}{es.Name}") select item).ToList(); if (queryScopesService.Any()) { var discoCache = _consentDiscoveryCacheAccessor.GetConsentDiscoveryCache(es); var doco = await discoCache.GetAsync(); List <string> scopes = null; switch (doco.AuthorizationType) { case Constants.AuthorizationTypes.Implicit: scopes = null; break; case Constants.AuthorizationTypes.Subject: scopes = null; break; case Constants.AuthorizationTypes.SubjectAndScopes: scopes = queryScopes; break; } if (doco.AuthorizationType != Constants.AuthorizationTypes.Implicit) { var request = new ConsentAuthorizeRequest { AuthorizeType = doco.AuthorizationType, Scopes = scopes, Subject = NameIdentifier }; var response = await _consentExternalService.PostAuthorizationRequestAsync(doco, request); var consentResponseContainer = new ConsentResponseContainer() { ExternalServiceEntity = es, DiscoveryDocument = doco, Request = request, Response = response }; ConsentResponseContainers.Add(consentResponseContainer); } else { ConsentResponseContainers.Add(new ConsentResponseContainer { ExternalServiceEntity = es, DiscoveryDocument = doco, Request = null, Response = null }); } } } var finalScopes = (from item in ConsentResponseContainers where item.Response.Authorized == true from scope in item.Response.Scopes select scope).ToList(); var claims = (from item in ConsentResponseContainers where item.Response.Authorized == true && item.Response.Claims != null from claim in item.Response.Claims let c = new ConsentAuthorizeClaim { Type = $"{item.ExternalServiceEntity.Name}.{claim.Type}", Value = claim.Value } select c) .DistinctBy(p => new { p.Type, p.Value }) .ToList(); var customs = (from item in ConsentResponseContainers where item.Response.Authorized == true && item.Response.CustomPayload != null let c = new CustomPayloadContainer { Name = $"{item.ExternalServiceEntity.Name}", CustomPayload = item.Response.CustomPayload } select c).ToList(); var docoTokenService = await _tokenServiceDiscoveryCache.GetAsync(); ArbitraryTokenTokenRequestV2 = new ArbitraryTokenTokenRequestV2() { Address = docoTokenService.TokenEndpoint, ClientId = _FluffyBunny4TokenServiceConfiguration.ClientId, ClientSecret = _FluffyBunny4TokenServiceConfiguration.ClientSecret, Subject = NameIdentifier, Scope = new HashSet <string>(), ArbitraryClaims = new Dictionary <string, List <string> >(), ArbitraryAmrs = new List <string>(), ArbitraryAudiences = new List <string>(), CustomPayload = null }; if (customs.Any()) { Dictionary <string, object> customMap = new Dictionary <string, object>(); foreach (var custom in customs) { customMap[custom.Name] = custom.CustomPayload; } ArbitraryTokenTokenRequestV2.CustomPayload = customMap; } foreach (var item in finalScopes) { ArbitraryTokenTokenRequestV2.Scope.Add(item); } foreach (var claim in claims) { if (!ArbitraryTokenTokenRequestV2.ArbitraryClaims.ContainsKey(claim.Type)) { ArbitraryTokenTokenRequestV2.ArbitraryClaims[claim.Type] = new List <string>(); } ArbitraryTokenTokenRequestV2.ArbitraryClaims[claim.Type].Add(claim.Value); } JsonArbitraryTokenTokenRequestV2 = _serializer.Serialize(ArbitraryTokenTokenRequestV2); var httpClient = new HttpClient(); var tokenPayload = await _fluffyBunnyTokenService.RequestArbitraryTokenAsync(httpClient, ArbitraryTokenTokenRequestV2); }