Example #1
0
        private async Task UnregisterSession(Mode mode)
        {
            logger.LogDebug("Unregister session");

            var sessionId = authStateAccessor.Value;

            if (string.IsNullOrEmpty(sessionId))
            {
                return;
            }

            var registerPath = $"/service/{mode.ToString().ToLowerInvariant()}/user/unregister/{sessionId}";
            var auth         = AuthorizationHeaderFactory.Create(authConfig.ClientId, authConfig.WebApiKey, registerPath, DateTime.UtcNow);

            var absUrl  = authConfig.RovaHost + registerPath;
            var request = new HttpRequestMessage(HttpMethod.Get, absUrl)
            {
                Headers =
                {
                    { "X-AsiointivaltuudetAuthorization", auth }
                }
            };

            var response = await httpClient.SendAsync(request);

            response.EnsureSuccess();

            logger.LogInformation("Session unregistered");
        }
Example #2
0
        private async Task <SuomiFiAuthorizationResult> GetAuthorization(string sessionId, string accessToken, GetDelegateResponse principal)
        {
            var resourceUrl         = $"/service/hpa/api/authorization/{sessionId}/{principal.PersonId}?requestId={requestId}&endUserId={userId}";
            var checksumHeaderValue = AuthorizationHeaderFactory.Create(authConfig.ClientId, authConfig.WebApiKey, resourceUrl, DateTime.UtcNow);
            var absUrl = authConfig.RovaHost + resourceUrl;

            var request = new HttpRequestMessage(HttpMethod.Get, absUrl)
            {
                Headers =
                {
                    { "Authorization",                    "Bearer " + accessToken },
                    { "X-AsiointivaltuudetAuthorization", checksumHeaderValue     }
                }
            };

            var result = await GetObject <AuthorizationResult>(request);

            var fullResult = new SuomiFiAuthorizationResult {
                Name     = principal.Name,
                PersonId = principal.PersonId,
                Allowed  = result.Result == "ALLOWED"
            };

            return(fullResult);
        }
Example #3
0
        private async Task <OAuthResponse> ChangeCodeToToken(string code, string callbackUri)
        {
            var auth    = AuthorizationHeaderFactory.CreateBasicHeader(authConfig.ClientId, authConfig.OAuthSecret);
            var absUrl  = authConfig.RovaHost + "/oauth/token?code=" + code + "&grant_type=authorization_code&redirect_uri=" + callbackUri;
            var request = new HttpRequestMessage(HttpMethod.Post, absUrl)
            {
                Headers =
                {
                    { "Authorization", auth }
                }
            };

            var result = await GetObject <OAuthResponse>(request);

            return(result);
        }
Example #4
0
        private async Task <GetDelegateResponse[]> GetDelegate(string sessionId, string accessToken)
        {
            var resourceUrl         = $"/service/hpa/api/delegate/{sessionId}?requestId={requestId}&endUserId={userId}";
            var absUrl              = authConfig.RovaHost + resourceUrl;
            var checksumHeaderValue = AuthorizationHeaderFactory.Create(authConfig.ClientId, authConfig.WebApiKey, resourceUrl, DateTime.UtcNow);
            var request             = new HttpRequestMessage(HttpMethod.Get, absUrl)
            {
                Headers =
                {
                    { "Authorization",                    "Bearer " + accessToken },
                    { "X-AsiointivaltuudetAuthorization", checksumHeaderValue     }
                }
            };

            var result = await GetObject <GetDelegateResponse[]>(request);

            return(result);
        }
Example #5
0
        private async Task <SuomiFiOrganizationResult[]> GetOrganizations(string sessionId, string accessToken)
        {
            var resourceUrl         = $"/service/ypa/api/organizationRoles/{sessionId}?requestId={requestId}&endUserId={userId}";
            var absUrl              = authConfig.RovaHost + resourceUrl;
            var checksumHeaderValue = AuthorizationHeaderFactory.Create(authConfig.ClientId, authConfig.WebApiKey, resourceUrl, DateTime.UtcNow);
            var request             = new HttpRequestMessage(HttpMethod.Get, absUrl)
            {
                Headers =
                {
                    { "Authorization",                    "Bearer " + accessToken },
                    { "X-AsiointivaltuudetAuthorization", checksumHeaderValue     }
                }
            };

            var result = await GetObject <OrganizationResult[]>(request);

            return(result.Select(x => new SuomiFiOrganizationResult {
                Name = x.Name,
                BusinessId = x.Identifier,
                Roles = x.Roles
            }).ToArray());
        }