예제 #1
0
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse GetAtcc(IApiRequest pApiReq)
        {
            string clientId = pApiReq.GetQueryValue(AccessClientIdParam, false);
            string secret   = pApiReq.GetQueryValue(AccessClientSecretParam, false);
            string redirUri = pApiReq.GetQueryValue(AccessRedirectUriParam, false);

            return(ExecuteAcc(pApiReq, OauthAccessOperation.GrantTypeCc,
                              clientId, secret, null, null, redirUri));
        }
예제 #2
0
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse GetAtr(IApiRequest pApiReq)
        {
            string refresh  = pApiReq.GetQueryValue(AccessRefreshTokenParam, false);
            string secret   = pApiReq.GetQueryValue(AccessClientSecretParam, false);
            string redirUri = pApiReq.GetQueryValue(AccessRedirectUriParam, false);

            return(ExecuteAcc(pApiReq, OauthAccessOperation.GrantTypeRt,
                              null, secret, null, refresh, redirUri));
        }
예제 #3
0
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse DoRemoveMember(IApiRequest pApiReq)
        {
            Func <object> getResp = (() => {
                var op = new InternalRemoveMemberOperation();
                op.Perform(pApiReq.OpCtx,
                           pApiReq.GetQueryValue("pass", false),
                           pApiReq.GetQueryValue("memId", false),
                           pApiReq.GetQueryValue("delete", false));
                return(op.GetResult());
            });

            var exec = new JsonExecutor <object>(pApiReq, getResp);

            return(exec.Execute());
        }
예제 #4
0
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse PostLoginScope(IApiRequest pApiReq, bool pAllow)
        {
            Action <IApiResponse> getResp = (apiResp => {
                string client = pApiReq.GetQueryValue(LoginClientIdParam, false);
                string redirUri = pApiReq.GetQueryValue(LoginRedirectUriParam, false);

                var op = new OauthLoginPostOperation();
                OauthLoginResult result = op.ExecuteScope(pApiReq.OpCtx, new OauthLoginTasks(),
                                                          client, redirUri, pAllow);

                apiResp.RedirectUrl = BuildRedirectUri(result.Redirect, result.Code,
                                                       pApiReq.GetQueryValue(LoginStateParam, false));
            });

            var exec = new CustomExecutor(pApiReq, getResp, OnLoginException);

            return(exec.Execute());
        }
예제 #5
0
        /*--------------------------------------------------------------------------------------------*/
        private static bool OnLoginException(IApiRequest pReq, IApiResponse pResp, Exception pEx)
        {
            FabOauthError fabErr;

            if (pEx is OauthException)
            {
                fabErr = (pEx as OauthException).OauthError;
            }
            else
            {
                fabErr = FabOauthError.ForInternalServerError();
                Log.Fatal("Unhandled OAuth Login Exception", pEx);
            }

            string redirUri = pReq.GetQueryValue(LoginRedirectUriParam, false);
            string state    = pReq.GetQueryValue(LoginStateParam, false);

            pResp.RedirectUrl = BuildRedirectUri(fabErr, redirUri, state);
            return(true);
        }
예제 #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse DoSetupDatabase(IApiRequest pApiReq)
        {
            Func <object> getResp = (() => {
                var op = new InternalInitDbOperation();
                op.Perform(pApiReq.OpCtx, pApiReq.GetQueryValue("pass", false));
                return(op.GetResult());
            });

            var exec = new JsonExecutor <object>(pApiReq, getResp);

            return(exec.Execute());
        }
예제 #7
0
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse PostLoginLogin(IApiRequest pApiReq)
        {
            Action <IApiResponse> getResp = (apiResp => {
                string user = pApiReq.GetFormValue(LoginUsername, true);
                string pass = pApiReq.GetFormValue(LoginPassword, true);
                bool rem = (pApiReq.GetFormValue(LoginRememberMe, false) == "1");

                string clientId = pApiReq.GetQueryValue(LoginClientIdParam, false);
                string redirUri = pApiReq.GetQueryValue(LoginRedirectUriParam, false);

                var op = new OauthLoginPostOperation();
                OauthLoginResult result = op.ExecuteLogin(pApiReq.OpCtx, new OauthLoginTasks(),
                                                          clientId, redirUri, user, pass);

                if (result.ShowLoginPage)
                {
                    apiResp.Html = new LoginPageView(result).ToHtml();
                    return;
                }

                if (result.Code != null)
                {
                    apiResp.RedirectUrl = BuildRedirectUri(result.Redirect, result.Code,
                                                           pApiReq.GetQueryValue(LoginStateParam, false));
                }
                else
                {
                    apiResp.Html = new LoginScopeView(result).ToHtml();
                }

                apiResp.SetUserCookie(result.LoggedUserId, rem);
            });

            var exec = new CustomExecutor(pApiReq, getResp, OnLoginException);

            return(exec.Execute());
        }
예제 #8
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse GetLogout(IApiRequest pApiReq)
        {
            Func <FabOauthLogout> getResp = (() => {
                string token = pApiReq.GetQueryValue(LogoutAccessTokenParam, false);

                var op = new OauthLogoutOperation();
                return(op.Execute(pApiReq.OpCtx, new OauthLogoutTasks(), token));
            });

            var          exec = new JsonExecutor <FabOauthLogout>(pApiReq, getResp);
            IApiResponse resp = exec.Execute();

            resp.SetUserCookie(null, false);
            return(resp);
        }
예제 #9
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse GetAt(IApiRequest pApiReq)
        {
            string grant    = pApiReq.GetQueryValue(AccessGrantTypeParam, false);
            string clientId = pApiReq.GetQueryValue(AccessClientIdParam, false);
            string secret   = pApiReq.GetQueryValue(AccessClientSecretParam, false);
            string code     = pApiReq.GetQueryValue(AccessCodeParam, false);
            string refresh  = pApiReq.GetQueryValue(AccessRefreshTokenParam, false);
            string redirUri = pApiReq.GetQueryValue(AccessRedirectUriParam, false);

            return(ExecuteAcc(pApiReq, grant, clientId, secret, code, refresh, redirUri));
        }
예제 #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static IApiResponse GetLogin(IApiRequest pApiReq)
        {
            string incomingError = pApiReq.GetQueryValue("error", false);

            if (incomingError != null)
            {
                string errDesc = pApiReq.GetQueryValue("error_description", false);

                return(new ApiResponse {
                    Html = new LoginErrorView(incomingError, errDesc).ToHtml()
                });
            }

            ////

            Action <IApiResponse> getResp = (apiResp => {
                string respType = pApiReq.GetQueryValue(LoginResponseTypeParam, false);
                string clientId = pApiReq.GetQueryValue(LoginClientIdParam, false);
                string redirUri = pApiReq.GetQueryValue(LoginRedirectUriParam, false);
                string switchMode = pApiReq.GetQueryValue(LoginSwitchModeParam, false);

                var op = new OauthLoginGetOperation();
                OauthLoginResult result = op.Execute(pApiReq.OpCtx, new OauthLoginTasks(),
                                                     clientId, redirUri, respType, switchMode);

                if (result.ShowLoginPage)
                {
                    apiResp.Html = new LoginPageView(result).ToHtml();
                    return;
                }

                if (result.Code != null)
                {
                    apiResp.RedirectUrl = BuildRedirectUri(result.Redirect, result.Code,
                                                           pApiReq.GetQueryValue(LoginStateParam, false));
                    return;
                }

                apiResp.Html = new LoginScopeView(result).ToHtml();
            });

            var exec = new CustomExecutor(pApiReq, getResp, OnLoginException);

            return(exec.Execute());
        }