/Controllers/AuthenticationController.cs
C# | 69 lines | 53 code | 11 blank | 5 comment | 0 complexity | af606894b831a37be2ca8e1d46d7037a MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Configuration;
- using System.Web.Http;
- using Newtonsoft.Json.Linq;
- namespace HCHunchApp.Web.Controllers
- {
- public class AuthenticationController : ApiController
- {
- private class AuthResponse
- {
- public string status { get; set; }
- public string ok { get; set; }
- public string auth_token { get; set; }
- public string user_id { get; set; }
- }
- // GET api/authentication
- public IEnumerable<string> Get()
- {
- return new string[] { "value1", "value2" };
- }
- // GET api/authentication/5
- public string Get(string id)
- {
- var auth_sig = WebConfigurationManager.AppSettings["auth_sig"];
- var app_id = WebConfigurationManager.AppSettings["app_id"];
- var getAuthTokenUrl = WebConfigurationManager.AppSettings["get_auth_token_url"];
- var url = String.Format(getAuthTokenUrl, app_id, id, auth_sig);
- var authTokenRequest = (HttpWebRequest)WebRequest.Create(url);
- authTokenRequest.ContentType = "application/json; charset=utf-8";
- var authTokenResponse = (HttpWebResponse)authTokenRequest.GetResponse();
- var responseData = new JObject();
- using (var sr = new StreamReader(authTokenResponse.GetResponseStream()))
- {
- var data = sr.ReadToEnd();
- responseData = JObject.Parse(data);
- }
- var auth_token = (string)responseData["auth_token"];
- return auth_token;
- }
- // POST api/authentication
- public void Post([FromBody]string value)
- {
- }
- // PUT api/authentication/5
- public void Put(int id, [FromBody]string value)
- {
- }
- // DELETE api/authentication/5
- public void Delete(int id)
- {
- }
- }
- }