/// <summary> /// Registers a supported OAuth client with the specified consumer key and consumer secret. /// </summary> /// <param name="client">One of the supported OAuth clients.</param> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> public static void RegisterOAuthClient(BuiltInOAuthClient client, string consumerKey, string consumerSecret) { IAuthenticationClient authenticationClient; switch (client) { case BuiltInOAuthClient.LinkedIn: authenticationClient = new LinkedInClient(consumerKey, consumerSecret); break; case BuiltInOAuthClient.Twitter: authenticationClient = new TwitterClient(consumerKey, consumerSecret); break; case BuiltInOAuthClient.Facebook: authenticationClient = new FacebookClient(consumerKey, consumerSecret); break; case BuiltInOAuthClient.WindowsLive: authenticationClient = new WindowsLiveClient(consumerKey, consumerSecret); break; default: throw new ArgumentOutOfRangeException("client"); } RegisterClient(authenticationClient); }
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) })); }
public IHttpActionResult Live(JObject value) { var authInfo = value.ToObject <ExternalAuthInfo>(); if (authInfo == null || String.IsNullOrEmpty(authInfo.Code)) { Log.Error().Message("External login failed: Unable to get auth info.").Tag("External Login", "WindowsLive").Property("Auth Info", authInfo).ContextProperty("HttpActionContext", ActionContext).Write(); 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 }); return(ExternalLogin(client, authInfo)); }