PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Controllers/AuthenticationController.cs

https://github.com/mhenderson442/HC_LocalHunch
C# | 69 lines | 53 code | 11 blank | 5 comment | 0 complexity | af606894b831a37be2ca8e1d46d7037a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Web.Configuration;
  8. using System.Web.Http;
  9. using Newtonsoft.Json.Linq;
  10. namespace HCHunchApp.Web.Controllers
  11. {
  12. public class AuthenticationController : ApiController
  13. {
  14. private class AuthResponse
  15. {
  16. public string status { get; set; }
  17. public string ok { get; set; }
  18. public string auth_token { get; set; }
  19. public string user_id { get; set; }
  20. }
  21. // GET api/authentication
  22. public IEnumerable<string> Get()
  23. {
  24. return new string[] { "value1", "value2" };
  25. }
  26. // GET api/authentication/5
  27. public string Get(string id)
  28. {
  29. var auth_sig = WebConfigurationManager.AppSettings["auth_sig"];
  30. var app_id = WebConfigurationManager.AppSettings["app_id"];
  31. var getAuthTokenUrl = WebConfigurationManager.AppSettings["get_auth_token_url"];
  32. var url = String.Format(getAuthTokenUrl, app_id, id, auth_sig);
  33. var authTokenRequest = (HttpWebRequest)WebRequest.Create(url);
  34. authTokenRequest.ContentType = "application/json; charset=utf-8";
  35. var authTokenResponse = (HttpWebResponse)authTokenRequest.GetResponse();
  36. var responseData = new JObject();
  37. using (var sr = new StreamReader(authTokenResponse.GetResponseStream()))
  38. {
  39. var data = sr.ReadToEnd();
  40. responseData = JObject.Parse(data);
  41. }
  42. var auth_token = (string)responseData["auth_token"];
  43. return auth_token;
  44. }
  45. // POST api/authentication
  46. public void Post([FromBody]string value)
  47. {
  48. }
  49. // PUT api/authentication/5
  50. public void Put(int id, [FromBody]string value)
  51. {
  52. }
  53. // DELETE api/authentication/5
  54. public void Delete(int id)
  55. {
  56. }
  57. }
  58. }