public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request) { HttpRequestMessage requestMessage = new HttpRequestMessage(); requestMessage.Method = HttpMethod.Post; requestMessage.RequestUri = new Uri("https://ob.coutts.useinfinite.io/token"); requestMessage.Content = new FormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "authorization_code"), new KeyValuePair <string, string>("client_id", "TLWlvSLh_LrIifOg93FEavA6pejAosNAoS67IxxcsOA="), new KeyValuePair <string, string>("client_secret", "LDdy9kuYLAahzT3mBvAQz3NYfcg0tdrhkfOzDNnaS4A="), new KeyValuePair <string, string>("code", request.BodyParameters["code"]) }); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]); HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage); BankServiceResponse response = new BankServiceResponse() { StatusCode = responseMessage.StatusCode, ReasonPhrase = responseMessage.ReasonPhrase, Content = responseMessage.Content }; return(response); }
public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request) { HttpRequestMessage requestMessage = new HttpRequestMessage(); requestMessage.Method = HttpMethod.Post; requestMessage.RequestUri = new Uri("https://ob.sandbox.natwestinternational.com/token"); requestMessage.Content = new FormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "authorization_code"), new KeyValuePair <string, string>("client_id", "fGo_5jXCm6QSXc7qgZIZhhXEHU4ogEFjZY06ENnc1Io="), new KeyValuePair <string, string>("client_secret", "wMaOw3bsbVh_zS2q1QQLE3ju6BwBUObLMS1v9GtqQEE="), new KeyValuePair <string, string>("code", request.BodyParameters["code"]) }); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]); HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage); BankServiceResponse response = new BankServiceResponse() { StatusCode = responseMessage.StatusCode, ReasonPhrase = responseMessage.ReasonPhrase, Content = responseMessage.Content }; return(response); }
public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request) { HttpRequestMessage requestMessage = new HttpRequestMessage(); requestMessage.Method = HttpMethod.Post; requestMessage.RequestUri = new Uri("https://ob.natwest.useinfinite.io/token"); requestMessage.Content = new FormUrlEncodedContent( new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "authorization_code"), new KeyValuePair <string, string>("client_id", "wDK0S-Tn7W483OvWEuiSjzBAe2gGafQNzE8URZa7xWY="), new KeyValuePair <string, string>("client_secret", "9QD6OPRmlWjU9k5g27wpaQ51LpL4coTdLCZ_u6wsv5o="), new KeyValuePair <string, string>("code", request.BodyParameters["code"]) }); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]); HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage); BankServiceResponse response = new BankServiceResponse() { StatusCode = responseMessage.StatusCode, ReasonPhrase = responseMessage.ReasonPhrase, Content = responseMessage.Content }; return(response); }
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 <ConsentInfo> CreateAccountAccessConsents() { ConsentInfo result = null; BankServiceRequest request = new BankServiceRequest() { HeaderParameters = new Dictionary <string, string>() }; var cachedClient = await _cachingService.GetAsync <CacheClientModel>(_rackleClientCacheKey); request.HeaderParameters.Add("access_token", cachedClient.BankCodesClientTokens[Provider.Coutts.Value].AccessToken); BankServiceResponse response = await _bankService.CreateAccountAccessConsents(request); if (response.StatusCode == System.Net.HttpStatusCode.Created) { JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); result = new ConsentInfo() { ConsentId = responseJson.RootElement.GetProperty("Data").GetProperty("ConsentId").GetString(), CreationDateTime = responseJson.RootElement.GetProperty("Data").GetProperty("CreationDateTime").GetString(), Status = responseJson.RootElement.GetProperty("Data").GetProperty("Status").GetString(), StatusUpdateDateTime = responseJson.RootElement.GetProperty("Data").GetProperty("StatusUpdateDateTime").GetString(), }; } var cachedUser = await _cachingService.GetAsync <CacheUserModel>("UserId-" + _authContext.UserId); if (!cachedUser.BankCodesConsentInfos.ContainsKey(Provider.Coutts.Value)) { cachedUser.BankCodesConsentInfos.Add(Provider.Coutts.Value, result); } else { cachedUser.BankCodesConsentInfos[Provider.Coutts.Value] = result; } await _cachingService.SetAsync <CacheUserModel>("UserId-" + _authContext.UserId, cachedUser); return(result); }