public async Task <string> getToken(string collectionsId, string userId) { YodleeAuthReturn authReturn = new YodleeAuthReturn(); ReturnModel returnModel = new ReturnModel(); if (Check(collectionsId)) { authReturn = await authReturn.GetToken(GetLoginName(collectionsId)); if (authReturn == null) { ExceptionCatcher exceptionCatcher = new ExceptionCatcher(); exceptionCatcher.Catch("auth return null "); } returnModel.returnStr = authReturn.token.accessToken; } else { if (userId != "") { returnModel = await Register(userId, collectionsId); } } return(returnModel.returnStr); }
public async Task <YodleeAuthReturn> GetToken(string loginName) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("loginName", loginName); client.DefaultRequestHeaders.Add("Api-Version", "1.1"); var dict = new Dictionary <string, string>(); dict.Add("clientId", ClientID); dict.Add("secret", secret); dict.Add("Content-Type", "application/x-www-form-urlencoded"); var content = new FormUrlEncodedContent(dict); HttpResponseMessage response = await client.PostAsync(url + "/auth/token", content); if (response.IsSuccessStatusCode) { string tokenStr = await response.Content.ReadAsStringAsync(); YodleeAuthReturn responseToken = JsonConvert.DeserializeObject <YodleeAuthReturn>(tokenStr); return(responseToken); } else { string tokenStr = await response.Content.ReadAsStringAsync(); ExceptionCatcher exceptionCatcher = new ExceptionCatcher(); exceptionCatcher.Catch(tokenStr); } return(null); }
private async Task <YodleeAuthReturn> GetAdminAuth() { YodleeAuthReturn authReturn = new YodleeAuthReturn(); authReturn = await authReturn.GetToken(ADMIN); return(authReturn); }
private async Task <ReturnModel> Register(string userId, string collectionsId) { YodleeAuthReturn auth = await GetAdminAuth(); ReturnModel returnModel = new ReturnModel(); if (auth.token.accessToken != null) { YodleeModel yodleeModel = new YodleeModel(); if (!Check(collectionsId)) { yodleeModel = new YodleeModel(collectionsId, "New"); } else { yodleeModel = new YodleeModel(collectionsId, "Get"); } AspNetUsers user = new AspNetUsers(); UserNames userNames = user.getNames(userId); RegisterModel registerModel = new RegisterModel(yodleeModel.loginName, userNames); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Api-Version", "1.1"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", auth.token.accessToken); StringContent content = new StringContent(JsonConvert.SerializeObject(registerModel), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url + "/auth/register", content); if (response.IsSuccessStatusCode) { YodleeAuthReturn authReturn = new YodleeAuthReturn(); authReturn = await authReturn.GetToken(yodleeModel.loginName); returnModel.result = true; returnModel.returnStr = authReturn.token.accessToken; } else { string tokenStr = await response.Content.ReadAsStringAsync(); ExceptionCatcher exceptionCatcher = new ExceptionCatcher(); exceptionCatcher.Catch(tokenStr); returnModel.result = false; } } else { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch("No Token generated"); returnModel.result = false; } return(returnModel); }