public async Task processAuthentication() { var json = await( authEntity.getBaseUrl() + "/v1/authenticate" ).PostUrlEncodedAsync( new { username = authEntity.getUsername(), key = authEntity.getPassword() } ).ReceiveString(); HttpRequestResponse = json; }
static async Task <String> authenticate() { HttpClient client = new HttpClient(); var values = new Dictionary <string, string> { { "username", authEntity.getUsername() }, { "key", authEntity.getPassword() } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync((authEntity.getBaseUrl() + "/v1/authenticate"), content); var json = await response.Content.ReadAsStringAsync(); return(json); }
public void Authenticate() { WebRequestUtil wrUtil = new WebRequestUtil(new AuthorizationEntity("", "", "")); Dictionary <string, string> post_data = new Dictionary <string, string>(); post_data.Add("username", authEntity.getUsername()); post_data.Add("key", authEntity.getPassword()); String url = (authEntity.getBaseUrl() + "/v1/authenticate"); webResponse = wrUtil.postRequest(url, post_data); /*String url = (authEntity.getBaseUrl() + "/v1/authenticate"); * WebRequest request = WebRequest.Create(url); * request.Method = "POST"; * request.ContentType = "application/x-www-form-urlencoded"; * * // manual concat credentials * //String post_data = "username="******"&key=" + authEntity.getPassword(); * * // using string builder * StringBuilder formData = new StringBuilder(); * formData.AppendFormat("{0}={1}", "username", authEntity.getUsername()); * formData.AppendFormat("&{0}={1}", "key", authEntity.getPassword()); * String post_data = formData.ToString(); * * Stream stream = request.GetRequestStream(); * byte[] postArray = Encoding.ASCII.GetBytes(post_data); * stream.Write(postArray, 0, postArray.Length); * stream.Close(); * * StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); * string Result = sr.ReadToEnd(); * * webResponse = Result.ToString();*/ }
static void Main(string[] args) { AppConfigService configService = new AppConfigService(); AppConfig config = configService.getConfiguration(); /** * instantiate the AuthenticateEntity to store your credentials * for the AlphaOne API */ AuthenticateEntity authEntity = new AuthenticateEntity(); authEntity.setBaseUrl(config.api_base_url); authEntity.setUsername(config.username); authEntity.setPassword(config.password); /** * instantiate auth service then start authenticating */ AuthenticationService auth = new AuthenticationService(authEntity); /** * You have 3 Authentication types to choose * - using nuget package Flurl.Http * - using HttpClient class * - lastly using WebRequest * * by default, its set to Flurl.Http */ // auth.setAuthenticationType(AuthenticationService.AUTH_TYPE_FLURL); // auth.setAuthenticationType(AuthenticationService.AUTH_TYPE_HTTP_CLIENT); auth.setAuthenticationType(AuthenticationService.AUTH_TYPE_WEB_REQUEST); String response = auth.Authenticate(); Console.WriteLine(response + "\n"); // convert json string to object AuthenticationResponse result = JsonConvert.DeserializeObject <AuthenticationResponse>(response); /** * this will be the access class you need to use * to fetch the project list or details */ AUTHORIZATION = new AuthorizationEntity( authEntity.getBaseUrl(), authEntity.getUsername(), result.session_key ); /** * instantiate ProjectListService class and get the project list * based on different options like * - accepted project list * - list of projects based on forms * - like BC granted/issued form * - CCC issued * - VRFI/RFI/IR finalised * - alpha-goget integration project list * * view the class and will give you bunch of options * to get the project list */ ProjectListService list = new ProjectListService(AUTHORIZATION); ProjectListResponse objResponse = list.getAcceptedProjectList(); Console.WriteLine("Total Projects: " + objResponse.Data.TotalProjects + "\n"); MarkResponse markResponse; if (objResponse.Data.List.Length > 0) { foreach (ProjectListItemObject item in objResponse.Data.List) { Console.WriteLine("AlphaID: " + item.AlphaID); Console.WriteLine("ConsentID: " + item.ConsentNumber); Console.WriteLine("Flag: " + item.ApplicationFlag); Console.WriteLine("RequestKey: " + item.RequestKey); Console.WriteLine("\nMarking as done ..."); markResponse = list.markAcceptedProjectAsDone(item.AlphaID, item.ApplicationFlag, item.RequestKey); Console.WriteLine("\tResult: " + markResponse.Result); Console.WriteLine("\tMessage: " + markResponse.Message); Console.WriteLine("\tTimestamp: " + markResponse.Timestamp); if (markResponse.Result == "true") { Console.WriteLine("\tResponseID: " + markResponse.ResponseID); } break; } } Console.WriteLine("\n\nTesting on ALPHAONE-GOCOUNCIL ...\n\n\n"); /** * AlphaOne-GoCouncil Integration Sample */ objResponse = list.getAlphaGoProjectList(); Console.WriteLine("Total Projects: " + objResponse.Data.TotalProjects + "\n"); if (objResponse.Data.List.Length > 0) { foreach (ProjectListItemObject item in objResponse.Data.List) { Console.WriteLine("AlphaID: " + item.AlphaID); Console.WriteLine("ConsentID: " + item.ConsentNumber); Console.WriteLine("Flag: " + item.ApplicationFlag); Console.WriteLine("RequestKey: " + item.RequestKey); Console.WriteLine("\nMarking as done ..."); markResponse = list.markAlphaGoProjectAsDone(item.AlphaID, item.ApplicationFlag, item.RequestKey); Console.WriteLine("\tResult: " + markResponse.Result); Console.WriteLine("\tMessage: " + markResponse.Message); Console.WriteLine("\tTimestamp: " + markResponse.Timestamp); if (markResponse.Result == "true") { Console.WriteLine("\tResponseID: " + markResponse.ResponseID); } break; } } }