public IHttpActionResult Live(JObject value) { var authInfo = value.ToObject <ExternalAuthInfo>(); if (authInfo == null || String.IsNullOrEmpty(authInfo.Code)) { return(NotFound()); } if (String.IsNullOrEmpty(Settings.Current.MicrosoftAppId) || String.IsNullOrEmpty(Settings.Current.MicrosoftAppSecret)) { return(NotFound()); } var client = new WindowsLiveClient(new RequestFactory(), new RuntimeClientConfiguration { ClientId = Settings.Current.MicrosoftAppId, ClientSecret = Settings.Current.MicrosoftAppSecret, RedirectUri = authInfo.RedirectUri }); UserInfo userInfo; try { userInfo = client.GetUserInfo(authInfo.Code); } catch (Exception ex) { Log.Error().Exception(ex).Write(); //ex.ToExceptionless().MarkAsCritical().AddTags("External Login", "WindowsLive").AddObject(authInfo).Submit(); return(BadRequest("Unable to get user info.")); } User user; try { user = AddExternalLogin(userInfo); } catch (ApplicationException) { return(BadRequest("Account Creation is currently disabled.")); } catch (Exception ex) { Log.Error().Exception(ex).Write(); //ex.ToExceptionless().MarkAsCritical().AddTags("External Login", "WindowsLive").AddObject(authInfo).AddObject(userInfo).Submit(); return(BadRequest("An error occurred while processing user info.")); } if (user == null) { //_exceptionless.CreateLog(typeof(AuthController).Name, "Unable to process user info.", "Error").AddTags("External Login", "WindowsLive").AddObject(authInfo).AddObject(userInfo).Submit(); return(BadRequest("Unable to process user info.")); } if (!String.IsNullOrWhiteSpace(authInfo.InviteToken)) { AddInvitedUserToOrganization(authInfo.InviteToken, user); } return(Ok(new TokenResult { Token = GetToken(user) })); }
public IHttpActionResult Live(JObject value) { var authInfo = value.ToObject <ExternalAuthInfo>(); if (authInfo == null || String.IsNullOrEmpty(authInfo.Code)) { return(NotFound()); } if (String.IsNullOrEmpty(Settings.Current.MicrosoftAppId) || String.IsNullOrEmpty(Settings.Current.MicrosoftAppSecret)) { return(NotFound()); } var client = new WindowsLiveClient(new RequestFactory(), new RuntimeClientConfiguration { ClientId = Settings.Current.MicrosoftAppId, ClientSecret = Settings.Current.MicrosoftAppSecret, RedirectUri = authInfo.RedirectUri }); UserInfo userInfo; try { userInfo = client.GetUserInfo(authInfo.Code); } catch (Exception ex) { Log.Error().Exception(ex).Message("Unable to get user info.").Write(); return(BadRequest("Unable to get user info.")); } User user; try { user = AddExternalLogin(userInfo); } catch (Exception ex) { Log.Error().Exception(ex).Message("Unable to get user info.").Write(); return(BadRequest("An error occurred while processing user info.")); } if (user == null) { return(BadRequest("Unable to process user info.")); } if (!String.IsNullOrEmpty(authInfo.InviteToken)) { AddInvitedUserToOrganization(authInfo.InviteToken, user); } return(Ok(new { Token = GetToken(user) })); }