// GET: LogIn public async Task<string> Index(string email, string password, string username, string mobile) { try { var body = new AuthenticationModel { AccessToken = AppId.ToString(), Email = email, Password = password, UserName = username, MobilePhone = mobile }; var tokenResponse = await tokenClient.GetTokenAsync(body); if (tokenResponse.StatusCode == HttpStatusCode.OK) { var claims = await tokenClient.GetClaimsAsync(tokenResponse.AuthToken); return tokenResponse.AuthToken + "<br/>" + JsonConvert.SerializeObject(claims); } // set a query string param so UX can know unauth. See if you can use regular status code Response.Redirect("/?l=f"); return string.Empty; } catch(Exception ex) { return "An exception occured" + ex.Message; } }
/// <summary> /// Gets a Token from the Token Service /// </summary> /// <param name="authentication">The authentication body</param> /// <returns></returns> public async Task<TokenResponseModel> GetTokenAsync(AuthenticationModel authentication) { try { var response = await this.client.PostAsync<string>( "/token", TokenCryptoManager.Instance.Encrypt(JsonConvert.SerializeObject(authentication)), new TextMediaFormatter()); var tokenResponse = new TokenResponseModel { StatusCode = response.StatusCode }; var responseText = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK) { return new TokenResponseModel { StatusCode = response.StatusCode, AuthToken = responseText }; } else { return new TokenResponseModel { StatusCode = response.StatusCode, Message = responseText }; } } catch (Exception ex) { throw ex; } }