public ContactsGroup(string accessToken) { if (string.IsNullOrWhiteSpace(accessToken)) { throw new Exception("Access Token is required to get user info"); } var parameters = new Dictionary<string, string> { { "alt", "json" } }; response = Utils.MakeWebRequest(endpointUrl, parameters, false, accessToken); if (response != null) { var serializer = new JavaScriptSerializer(); var contactFeed = serializer.Deserialize<Dictionary<string, object>>(ToJsonString()); var feed = (Dictionary < string, object>)contactFeed["feed"]; var entry = (ArrayList)feed["entry"]; Entries = new List<Entry>(); foreach (Dictionary<string, object> entryItem in entry) { var id = (Dictionary<string, object>)entryItem["id"]; var title = (Dictionary <string, object>) entryItem["title"]; var group = new Entry { Id = (string) id["$t"], Name = (string) title["$t"] }; Entries.Add(group); } } }
protected override UserInfo ExtractUserInfo(HttpAuthResponse response) { UserInfo returnValue = null; if (response == null) { return(null); } try { if (!Utils.IsJson(response.ResponseString)) { throw new Exception($"String not in json format: {response.ResponseString}"); } var windowsLiveUserInfo = new JavaScriptSerializer().Deserialize <WindowsLiveInfo>(response.ResponseString); returnValue = new UserInfo { Id = windowsLiveUserInfo.Id, FullName = windowsLiveUserInfo.Name, FirstName = windowsLiveUserInfo.First_name, LastName = windowsLiveUserInfo.Last_name, Email = windowsLiveUserInfo.Emails.Account, Gender = windowsLiveUserInfo.Gender, SocialLink = windowsLiveUserInfo.Link, PictureUrl = $"https://apis.live.net/v5.0/{windowsLiveUserInfo.Id}/picture" }; } catch (Exception ex) { throw new Exception($"Unable to parse JSON response: {ex.Message}"); } return(returnValue); }
protected override UserInfo ExtractUserInfo(HttpAuthResponse response) { UserInfo returnValue = null; if (response == null) { return(null); } try { if (Utils.IsJson(response.ResponseString)) { throw new Exception($"String not in json format: {response.ResponseString}"); } var googleUserInfo = new JavaScriptSerializer().Deserialize <GoogleUserInfo>(response.ResponseString); returnValue = new UserInfo { Id = googleUserInfo.Id, FullName = googleUserInfo.Name, FirstName = googleUserInfo.Given_Name, LastName = googleUserInfo.Family_Name, Email = googleUserInfo.Email, Gender = googleUserInfo.Gender, Locale = googleUserInfo.Locale, SocialLink = googleUserInfo.Link, PictureUrl = googleUserInfo.Picture, Domain = googleUserInfo.Hd }; } catch (Exception ex) { throw new Exception($"Unable to parse JSON response: {ex.Message}"); } return(returnValue); }
public CalendarList(string accessToken) { if (string.IsNullOrWhiteSpace(accessToken)) { throw new Exception("Access Token is required to get user info"); } response = Utils.MakeWebRequest(endpointUrl, null, false, accessToken); if (response != null) { var serializer = new JavaScriptSerializer(); var calendarItems = serializer.Deserialize <CalendarItems>(ToJsonString()); CalendarItems = calendarItems.Items; } }
public void Post(string accessToken, string channel, string blocks) { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; if (string.IsNullOrWhiteSpace(accessToken)) { throw new Exception("Access Token is required to get user info"); } var parameters = new Dictionary <string, string>(); parameters.Add("channel", channel); parameters.Add("blocks", blocks); parameters.Add("token", accessToken); response = Utils.MakeWebRequest(endpointUrl, parameters, true, accessToken); }
public DomainUsers(string accessToken, Dictionary <string, string> parameters = null) { if (string.IsNullOrWhiteSpace(accessToken)) { throw new Exception("Access Token is required to get user info"); } if (parameters == null) { parameters = new Dictionary <string, string> { { "domain", "officeclip.com" } }; } response = Utils.MakeWebRequest(endpointUrl, parameters, false, accessToken); if (response != null) { var serializer = new JavaScriptSerializer(); var users = serializer.Deserialize <AdminDirectoryUsers>(ToJsonString()); Users = users.Users; } }
public List <Channel> GetChannelList(string accessToken) { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; List <Channel> retChannels = new List <Channel>(); if (string.IsNullOrWhiteSpace(accessToken)) { throw new Exception("Access Token is required to get user info"); } response = Utils.MakeWebRequest(endpointUrl, null, false, accessToken); if (response != null) { var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); var slackResponse = serializer.Deserialize <SlackMessageResponse>(ToJsonString()); retChannels = slackResponse.channels; } return(retChannels); }
private async void ProcessAuthResponse(HttpContext context, HttpAuthResponse authResponse) { _logger.LogInformation($"ProccessAuthResponse, StatusCode: {authResponse.StatusCode}"); var responseHeaders = context.Response.Headers; var requestHeaders = context.Request.Headers; // StatusCode context.Response.StatusCode = authResponse.StatusCode; // Headers if (!string.IsNullOrWhiteSpace(authResponse.AccessToken)) { responseHeaders.Set(HttpAuthAccessTokenHeader, authResponse.AccessToken); } if (!string.IsNullOrWhiteSpace(authResponse.SealedAccessToken)) { responseHeaders.Set(HttpAuthSealedAccessTokenHeader, authResponse.SealedAccessToken); } if (!string.IsNullOrWhiteSpace(authResponse.Nonce)) { responseHeaders.Set(HttpAuthNonceHeader, authResponse.Nonce); } if (!string.IsNullOrWhiteSpace(authResponse.CNonce)) { responseHeaders.Set(HttpAuthCNonceHeader, authResponse.CNonce); } if (!string.IsNullOrWhiteSpace(authResponse.OCNonce)) { responseHeaders.Set(HttpAuthOCNonceHeader, authResponse.OCNonce); } // Body if (authResponse.Body == null) { _logger.LogInformation("Without body"); return; } var acceptContentArray = requestHeaders.Get("Accept")?.Split(new char[] { ';' }); var acceptContent = (acceptContentArray?.Length > 0 ? acceptContentArray[0] : "").Split(new char[] { ',' }); if (acceptContent.Count(x => string.Compare(x, JsonMimeContentType, true) == 0) > 0) { _logger.LogInformation("With a JSON body"); context.Response.ContentType = $"{JsonMimeContentType}; charset=utf-8"; await context.Response.WriteAsync(convertObjectToJsonString(authResponse.Body)); } if (acceptContent.Count(x => string.Compare(x, XmlMimeContentType, true) == 0) > 0) { _logger.LogWarning("With a XML body"); context.Response.ContentType = $"{XmlMimeContentType}; charset=utf-8"; var xmlDoc = JsonConvert.DeserializeXNode(convertObjectToJsonString(authResponse.Body), null, true); xmlDoc.Declaration = new XDeclaration("1.0", "utf-8", "yes"); await context.Response.WriteAsync(xmlDoc.Declaration.ToString()); await context.Response.WriteAsync(xmlDoc.Root.ToString()); } }
public async Task Invoke(HttpContext context, IHostingEnvironment env, IAuthenticationService authenticationService) { RequestFluxType requestType = Unknown; HttpAuthResponse response = null; IHeaderDictionary headers = context.Request.Headers; try { requestType = GetRequestFluxType(context, _path); if (requestType == RequestAccessToken) { var appInstanceId = headers[HttpAuthAppInstanceIdHeader]; var seal = headers[HttpAuthSealHeader]; var accessToken = authenticationService.GetAccessToken(context.Request, appInstanceId, seal); if (accessToken == null) { response = new HttpUnauthorizedResponse(); } else { response = new HttpAccessTokenResponse(accessToken); } } if (requestType == ConfirmTokenNonce) { var appInstanceId = headers[HttpAuthAppInstanceIdHeader]; var accessTokenValue = headers[HttpAuthAccessTokenHeader]; var cNonce = headers[HttpAuthCNonceHeader]; var accessToken = authenticationService.ConfirmToken(context.Request, appInstanceId, accessTokenValue, cNonce); if (accessToken == null) { response = new HttpUnauthorizedResponse(); } else { response = new HttpConfirmTokenNonceResponse(accessToken); } } if (requestType == ResourceRequest) { var appInstanceId = headers[HttpAuthAppInstanceIdHeader]; var sealedAccessTokenValue = headers[HttpAuthSealedAccessTokenHeader]; var cNonce = headers[HttpAuthCNonceHeader]; if (!authenticationService.GrantAccess(context.Request, appInstanceId, sealedAccessTokenValue, cNonce)) { response = new HttpUnauthorizedResponse(); } } if (requestType == BadRequest) { response = new HttpBadRequestResponse(); } } catch (Exception exception) { response = new HttpExceptionResponse(exception); } if (response != null) { ProcessAuthResponse(context, response); return; } if (requestType != ResourceRequest) { var exception = new Exception($"Internal server error when dealing request {requestType.GetType().FullName}."); ProcessAuthResponse(context, new HttpExceptionResponse(exception)); return; } await _next(context); }