/// <summary> /// ExchangeAuthCode returns the completed userCredential back /// </summary> /// <param name="userCredential"></param> /// <returns></returns> private async Task <UserCredential> ExchangeAuthCode(UserCredential userCredential) { string apiResponse; AuthTokenResponse jsonResponse; AuthExchange authExchangeData = new AuthExchange(); authExchangeData.grant_type = "authorization_code"; authExchangeData.client_id = userCredential.CredentialsId; authExchangeData.client_secret = userCredential.ClientCredentials.ClientSecret; authExchangeData.redirect_uri = userCredential.ClientCredentials.RedirectUri; authExchangeData.code = userCredential.ExchangeCode; using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(authExchangeData), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync("https://auth.truelayer-sandbox.com/connect/token", content)) { apiResponse = await response.Content.ReadAsStringAsync(); jsonResponse = JsonConvert.DeserializeObject <AuthTokenResponse>(apiResponse); userCredential.AccessToken = jsonResponse.access_token; userCredential.ExpirationDate = jsonResponse.expires_in.ToString(); userCredential.RefreshToken = jsonResponse.refresh_token; } } return(userCredential); }
public async Task <ActionResult <Dictionary <string, string> > > RefreshToken(string refreshToken, string clientId, string clientSecret) { string apiResponse; Dictionary <string, string> jsonResponse; AuthExchange authExchangeData = new AuthExchange(); authExchangeData.grant_type = "refresh_token"; authExchangeData.client_id = clientId; authExchangeData.client_secret = clientSecret; authExchangeData.refresh_token = refreshToken; using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(authExchangeData), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync("https://auth.truelayer-sandbox.com/connect/token", content)) { apiResponse = await response.Content.ReadAsStringAsync(); jsonResponse = JsonConvert.DeserializeObject <Dictionary <string, string> >(apiResponse); } } return(jsonResponse); }