Пример #1
0
        public async Task <BaseAccessToken> ClientCredentialsAccessToken()
        {
            BaseAccessToken result = null;

            BankServiceRequest  request  = new BankServiceRequest();
            BankServiceResponse response = await _bankService.ClientCredentialsAccessToken(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

                result = new BaseAccessToken()
                {
                    AccessToken = responseJson.RootElement.GetProperty("access_token").GetString(),
                    TokenType   = responseJson.RootElement.GetProperty("token_type").GetString(),
                    ExpiresIn   = responseJson.RootElement.GetProperty("expires_in").GetInt64().ToString(),
                    Scope       = responseJson.RootElement.GetProperty("scope").GetString()
                };
            }

            var cachedClient = await _cachingService.GetAsync <CacheClientModel>(_rackleClientCacheKey);

            if (!cachedClient.BankCodesClientTokens.ContainsKey(Provider.Natwest.Value))
            {
                cachedClient.BankCodesClientTokens.Add(Provider.Natwest.Value, result);
            }
            else
            {
                cachedClient.BankCodesClientTokens[Provider.Natwest.Value] = result;
            }
            await _cachingService.SetAsync <CacheClientModel>(_rackleClientCacheKey, cachedClient);

            return(result);
        }
        public async Task <BaseAccessToken> AuthorizationCodeAccessToken(string code, string userId)
        {
            BaseAccessToken result = null;

            BankServiceRequest request = new BankServiceRequest()
            {
                BodyParameters   = new Dictionary <string, string>(),
                HeaderParameters = new Dictionary <string, string>()
            };

            request.BodyParameters.Add("code", code);
            request.HeaderParameters.Add("access_token", "");

            BankServiceResponse response = await _bankService.AuthorizationCodeAccessToken(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

                result = new BaseAccessToken()
                {
                    AccessToken  = responseJson.RootElement.GetProperty("access_token").GetString(),
                    TokenType    = responseJson.RootElement.GetProperty("token_type").GetString(),
                    ExpiresIn    = responseJson.RootElement.GetProperty("expires_in").GetInt64().ToString(),
                    Scope        = responseJson.RootElement.GetProperty("scope").GetString(),
                    RefreshToken = responseJson.RootElement.GetProperty("refresh_token").GetString()
                };
            }

            //var cachedUser = await _cachingService.GetAsync<CacheUserModel>("UserId-" + _authContext.UserId);
            var cachedUser = await _cachingService.GetAsync <CacheUserModel>("UserId-" + userId);

            if (!cachedUser.BankCodesTokens.ContainsKey(Provider.RBS.Value))
            {
                cachedUser.BankCodesTokens.Add(Provider.RBS.Value, result);
            }
            else
            {
                cachedUser.BankCodesTokens[Provider.RBS.Value] = result;
            }

            //await _cachingService.SetAsync<CacheUserModel>("UserId-" + _authContext.UserId, cachedUser);

            var customerProfileRequestIntegrationEvent = new CustomerProfileRequestIntegrationEvent {
                ProviderIdTokens = new Dictionary <int, string>(), UserId = Guid.Parse(userId)
            };
            await _cachingService.SetAsync <CacheUserModel>("UserId-" + userId, cachedUser);

            foreach (var rec in cachedUser.BankCodesTokens)
            {
                customerProfileRequestIntegrationEvent.ProviderIdTokens.Add(rec.Key, rec.Value.AccessToken);
            }

            await _integrationEventService.PublishThroughEventBusAsync(customerProfileRequestIntegrationEvent);

            return(result);
        }
        public async Task <ActionResult <UrlResponse> > CustomerLogin()
        {
            BaseAccessToken clientAccessTokenResult = await _clientOperationsBusinessLogic.ClientCredentialsAccessToken();

            ConsentInfo consentResult = await _clientOperationsBusinessLogic.CreateAccountAccessConsents();

            string customerLoginResult = await _clientOperationsBusinessLogic.CustomerLogin();

            var result = new UrlResponse {
                url = customerLoginResult
            };

            return(result);
        }