当前位置: 首页>>代码示例>>C#>>正文


C# OAuth2.AuthorizeRequest类代码示例

本文整理汇总了C#中Thinktecture.AuthorizationServer.OAuth2.AuthorizeRequest的典型用法代码示例。如果您正苦于以下问题:C# AuthorizeRequest类的具体用法?C# AuthorizeRequest怎么用?C# AuthorizeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AuthorizeRequest类属于Thinktecture.AuthorizationServer.OAuth2命名空间,在下文中一共展示了AuthorizeRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

        // GET /{appName}/oauth/authorize
        //
        public ActionResult Index(string appName, AuthorizeRequest request)
        {
            Tracing.Start("OAuth2 Authorize Endoint");

            // make sure application is registered
            var application = _config.FindApplication(appName);
            if (application == null)
            {
                Tracing.Error("Application not found: " + appName);
                return HttpNotFound();
            }

            ValidatedRequest validatedRequest;
            try
            {
                validatedRequest = new AuthorizeRequestValidator().Validate(application, request);
            }
            catch (AuthorizeRequestValidationException ex)
            {
                Tracing.Error("Aborting OAuth2 authorization request");
                return this.AuthorizeValidationError(ex);
            }

            if (validatedRequest.ShowConsent)
            {
                // show consent screen
                Tracing.Verbose("Showing consent screen");

                return View("Consent", validatedRequest);
            }

            Tracing.Verbose("No consent configured for application/client");
            return PerformGrant(validatedRequest);
        }
开发者ID:RomanDidenko,项目名称:Thinktecture.AuthorizationServer,代码行数:36,代码来源:AuthorizeController.cs

示例2: Index

        // GET /{appName}/oauth/authorize
        //
        public ActionResult Index(string appName, AuthorizeRequest request)
        {
            Tracing.Start("OAuth2 Authorize Endoint");

            // make sure application is registered
            var application = _config.FindApplication(appName);
            if (application == null)
            {
                Tracing.Error("Application not found: " + appName);
                return HttpNotFound();
            }

            ValidatedRequest validatedRequest;
            try
            {
                validatedRequest = new AuthorizeRequestValidator().Validate(application, request);
            }
            catch (AuthorizeRequestValidationException ex)
            {
                Tracing.Error("Aborting OAuth2 authorization request");
                return this.AuthorizeValidationError(ex);
            }

            if (validatedRequest.ShowConsent)
            {
                validatedRequest.RememberOptions = GetRememberOptions(application);

                // todo: check first if a remembered consent decision exists
                if (validatedRequest.ResponseType == OAuthConstants.ResponseTypes.Token)
                {
                    var handle = _handleManager.Find(
                        ClaimsPrincipal.Current.GetSubject(),
                        validatedRequest.Client,
                        validatedRequest.Application,
                        validatedRequest.Scopes,
                        StoredGrantType.ConsentDecision);

                    if (handle != null)
                    {
                        Tracing.Verbose("Stored consent decision found.");

                        return PerformGrant(validatedRequest);
                    }
                }

                // show consent screen
                Tracing.Verbose("Showing consent screen");
                return View("Consent", validatedRequest);
            }

            Tracing.Verbose("No consent configured for application/client");

            
            // workaround for bug #139
            validatedRequest.RequestedRefreshTokenExpiration = DateTime.UtcNow.AddYears(50);
            return PerformGrant(validatedRequest);
        }
开发者ID:Excape,项目名称:Thinktecture.AuthorizationServer,代码行数:59,代码来源:AuthorizeController.cs

示例3: HandleConsentResponse

        public ActionResult HandleConsentResponse(string appName, string button, string[] scopes, AuthorizeRequest request, int? rememberDuration = null)
        {
            Tracing.Start("OAuth2 Authorize Endoint - Consent response");

            // make sure application is registered
            var application = _config.FindApplication(appName);
            if (application == null)
            {
                Tracing.Error("Application not found: " + appName);
                return HttpNotFound();
            }

            if (button == "no")
            {
                Tracing.Information("User denies access token request.");
                return new ClientErrorResult(new Uri(request.redirect_uri), OAuthConstants.Errors.AccessDenied, request.response_type, request.state);
            }

            if (button == "yes")
            {
                Tracing.Information("User allows access token request.");

                ValidatedRequest validatedRequest;
                try
                {
                    validatedRequest = new AuthorizeRequestValidator().Validate(application, request);
                }
                catch (AuthorizeRequestValidationException ex)
                {
                    Tracing.Error("Aborting OAuth2 authorization request");
                    return this.AuthorizeValidationError(ex);
                }

                if (scopes == null || scopes.Length == 0)
                {
                    ModelState.AddModelError("", "Please choose at least one permission.");
                    return View("Consent", validatedRequest);
                }

                // todo: parse scopes form post and substitue scopes
                validatedRequest.Scopes.RemoveAll(x => !scopes.Contains(x.Name));
                var grantResult = PerformGrant(validatedRequest);
                if (grantResult != null) return grantResult;
            }

            return new ClientErrorResult(
                new Uri(request.redirect_uri), 
                OAuthConstants.Errors.InvalidRequest, 
                request.response_type, 
                request.state);
        }
开发者ID:RomanDidenko,项目名称:Thinktecture.AuthorizationServer,代码行数:51,代码来源:AuthorizeController.cs

示例4: ValidRequestMultipleScope

        public void ValidRequestMultipleScope()
        {
            var validator = new AuthorizeRequestValidator(_clientManager);
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "codeclient",
                response_type = "code",
                scope = "read search",
                redirect_uri = "https://prod.local"
            };

            var result = validator.Validate(app, request);
        }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:14,代码来源:AuthorizeRequest_Validation_Code.cs

示例5: ValidRequestMultipleScope

        public void ValidRequestMultipleScope()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "implicitclient",
                response_type = "token",
                scope = "read browse",
                redirect_uri = "https://test2.local"
            };

            var result = validator.Validate(app, request);
        }
开发者ID:Griimm,项目名称:Thinktecture.AuthorizationServer,代码行数:14,代码来源:AuthorizeRequest_Validation_Token.cs

示例6: DisabledClient

        public void DisabledClient()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "disabledclient",
                response_type = "code",
                scope = "read",
                redirect_uri = "https://prod.local"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestResourceOwnerException ex)
            {
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:danielvanwyk,项目名称:AuthorizationServer,代码行数:23,代码来源:AuthorizeRequest_Validation_General.cs

示例7: MissingRedirectUri

        public void MissingRedirectUri()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "codeclient",
                response_type = "code",
                scope = "read"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestResourceOwnerException ex)
            {
                // todo: check error code
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:Excelsior-Charles,项目名称:Thinktecture.AuthorizationServer,代码行数:23,代码来源:Authorize_Request_Validation_General.cs

示例8: UnauthorizedResponseType

        public void UnauthorizedResponseType()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "implicitclient",
                response_type = "code",
                scope = "read",
                redirect_uri = "https://test2.local"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestClientException ex)
            {
                Assert.IsTrue(ex.Error == OAuthConstants.Errors.UnsupportedResponseType);
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:Excelsior-Charles,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:Authorize_Request_Validation_Token.cs

示例9: UnauthorizedRedirectUri

        public void UnauthorizedRedirectUri()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "implicitclient",
                response_type = "token",
                scope = "read",
                redirect_uri = "https://unauthorized.com"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestResourceOwnerException ex)
            {
                // todo: check error code
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:Griimm,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:AuthorizeRequest_Validation_Token.cs

示例10: ValidateTokenResponseType

 private void ValidateTokenResponseType(ValidatedRequest validatedRequest, AuthorizeRequest request)
 {
     if (validatedRequest.Client.Flow != OAuthFlow.Implicit)
     {
         throw new AuthorizeRequestClientException(
             "response_type is not allowed: " + request.response_type,
             new Uri(validatedRequest.RedirectUri.Uri),
             OAuthConstants.Errors.UnsupportedResponseType,
             request.response_type,
             validatedRequest.State);
     }
 }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:12,代码来源:AuthorizeRequestValidator.cs

示例11: MalformedRedirectUri1

        public void MalformedRedirectUri1()
        {
            var validator = new AuthorizeRequestValidator(_clientManager);
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "codeclient",
                response_type = "code",
                scope = "read",
                redirect_uri = "https:/prod.local"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestResourceOwnerException ex)
            {
                // todo: check error code
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:AuthorizeRequest_Validation_General.cs

示例12: UnauthorizedResponseType

        public void UnauthorizedResponseType()
        {
            var validator = new AuthorizeRequestValidator(_clientManager);
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "codeclient",
                response_type = "token",
                scope = "read",
                redirect_uri = "https://prod.local"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestClientException ex)
            {
                Assert.AreEqual(OAuthConstants.Errors.UnsupportedResponseType, ex.Error);
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:AuthorizeRequest_Validation_Code.cs

示例13: UnauthorizedScopeMultiple

        public void UnauthorizedScopeMultiple()
        {
            var validator = new AuthorizeRequestValidator();
            var app = _testConfig.FindApplication("test");
            var request = new AuthorizeRequest
            {
                client_id = "implicitclient",
                response_type = "token",
                scope = "read write",
                redirect_uri = "https://test2.local"
            };

            try
            {
                var result = validator.Validate(app, request);
            }
            catch (AuthorizeRequestClientException ex)
            {
                Assert.AreEqual(OAuthConstants.Errors.InvalidScope, ex.Error);
                return;
            }

            Assert.Fail("No exception thrown.");
        }
开发者ID:Griimm,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:AuthorizeRequest_Validation_Token.cs

示例14: ValidateCodeResponseType

        private void ValidateCodeResponseType(ValidatedRequest validatedRequest, AuthorizeRequest request)
        {
            // make sure response type allowed for this client
            if (validatedRequest.Client.Flow != OAuthFlow.Code)
            {
                throw new AuthorizeRequestClientException(
                   "response_type is not allowed: " + request.response_type,
                   new Uri(validatedRequest.RedirectUri.Uri),
                   OAuthConstants.Errors.UnsupportedResponseType,
                   request.response_type,
                   validatedRequest.State);
            }

            if (validatedRequest.Client.AllowRefreshToken && validatedRequest.Application.AllowRefreshToken)
            {
                Tracing.Information("The request allows arefresh token.");
                validatedRequest.RequestingRefreshToken = true;
            }

            if (validatedRequest.Client.RequireConsent || validatedRequest.Application.RequireConsent)
            {
                Tracing.Information("Consent is required.");
                validatedRequest.ShowConsent = true;
            }
        }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:25,代码来源:AuthorizeRequestValidator.cs

示例15: ValidateScopes

        private static void ValidateScopes(AuthorizeRequest request, ValidatedRequest validatedRequest)
        {
            // validate scopes
            if (string.IsNullOrEmpty(request.scope))
            {
                throw new AuthorizeRequestClientException(
                    "Missing scope.",
                    new Uri(validatedRequest.RedirectUri.Uri),
                    OAuthConstants.Errors.InvalidScope,
                    validatedRequest.ResponseType,
                    validatedRequest.State);
            }

            var requestedScopes = request.scope.Split(' ').ToList();
            List<Scope> resultingScopes;

            if (validatedRequest.Application.Scopes.TryValidateScopes(validatedRequest.Client.ClientId, requestedScopes, out resultingScopes))
            {
                validatedRequest.Scopes = resultingScopes;
                Tracing.InformationFormat("Requested scopes: {0}", request.scope);
            }
            else
            {
                throw new AuthorizeRequestClientException(
                    "Invalid scope.",
                    new Uri(validatedRequest.RedirectUri.Uri),
                    OAuthConstants.Errors.InvalidScope,
                    validatedRequest.ResponseType,
                    validatedRequest.State);
            }
        }
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:31,代码来源:AuthorizeRequestValidator.cs


注:本文中的Thinktecture.AuthorizationServer.OAuth2.AuthorizeRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。