Exemplo n.º 1
0
        public IHttpActionResult GitHub(JObject value)
        {
            var authInfo = value.ToObject <ExternalAuthInfo>();

            if (authInfo == null || String.IsNullOrEmpty(authInfo.Code))
            {
                return(NotFound());
            }

            if (String.IsNullOrEmpty(Settings.Current.GitHubAppId) || String.IsNullOrEmpty(Settings.Current.GitHubAppSecret))
            {
                return(NotFound());
            }

            var client = new GitHubWithPrivateEmailsClient(new RequestFactory(), new RuntimeClientConfiguration {
                ClientId     = Settings.Current.GitHubAppId,
                ClientSecret = Settings.Current.GitHubAppSecret,
                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", "GitHub").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", "GitHub").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", "GitHub").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)
            }));
        }
Exemplo n.º 2
0
        public IHttpActionResult GitHub(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", "GitHub").Property("Auth Info", authInfo).ContextProperty("HttpActionContext", ActionContext).Write();
                return(NotFound());
            }

            if (String.IsNullOrEmpty(Settings.Current.GitHubAppId) || String.IsNullOrEmpty(Settings.Current.GitHubAppSecret))
            {
                return(NotFound());
            }

            var client = new GitHubWithPrivateEmailsClient(new RequestFactory(), new RuntimeClientConfiguration {
                ClientId     = Settings.Current.GitHubAppId,
                ClientSecret = Settings.Current.GitHubAppSecret,
                RedirectUri  = authInfo.RedirectUri
            });

            return(ExternalLogin(client, authInfo));
        }