public SessionTokenResponse Put([FromBody] ClientSessionRequest request) { SessionTokenResponse response = new SessionTokenResponse(); try { if (request != null) { if (!String.IsNullOrEmpty(request.username) && !String.IsNullOrEmpty(request.password)) { DB db = new DB(); response = db.GetSessionToken(request); } else { response.message = new Message("0014", "Ocurrio un error. Todos los datos son requeridos", null); } } else { response.message = new Message("0013", "Ocurrio un error. El body de la peticion es requerido", null); } } catch (Exception ex) { response.message = new Message("0012", "Ocurrio un error.", ex); } return(response); }
public SessionTokenResponse GetSessionToken(ClientSessionRequest sessionRequest) { SessionTokenResponse response = new SessionTokenResponse(); var answer = "0"; try { Open(); command = new SqlCommand("dbo.getUserSessionId", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@username", sessionRequest.username); command.Parameters.AddWithValue("@password", sessionRequest.password); reader = command.ExecuteReader(); while (reader.Read()) { answer = reader.GetFieldValue <string>(0); } Close(); if (answer != "0") { response.token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(answer.ToString())); response.message = new Message("0000", "Transaccion exitosa", null); } else { response.message = new Message("0016", "Transaccion fallida", null); } } catch (Exception ex) { response.message = new Message("0015", "Transaccion fallida.", ex); } return(response); }
public static async Task <NintendoAccount> Login(AuthorizationRequest request, string session_token_code, string grant_type) { // Create the form contents FormUrlEncodedContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("client_id", request.client_id), new KeyValuePair <string, string>("session_token_code", session_token_code), new KeyValuePair <string, string>("session_token_code_verifier", request.code_verifier) }); // Send the request HttpResponseMessage response = await httpHelper.POSTRequest(ACCOUNTS_BASE_URL + "/connect/1.0.0/api/session_token", content); response.EnsureSuccessStatusCode(); // Deserialize the response SessionTokenResponse sessionResponse = await HttpHelper.DeserializeResponse <SessionTokenResponse>(response); // Pass this data to the final login method return(await Login(request.client_id, sessionResponse.session_token, grant_type)); }