本文整理汇总了C#中Thinktecture.AuthorizationServer.OAuth2.AuthorizeRequest类的典型用法代码示例。如果您正苦于以下问题:C# AuthorizeRequest类的具体用法?C# AuthorizeRequest怎么用?C# AuthorizeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthorizeRequest类属于Thinktecture.AuthorizationServer.OAuth2命名空间,在下文中一共展示了AuthorizeRequest类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: NonSslRedirectUri
public void NonSslRedirectUri()
{
var validator = new AuthorizeRequestValidator();
var app = _testConfig.FindApplication("test");
var request = new AuthorizeRequest
{
client_id = "codeclient",
response_type = "code",
scope = "read",
redirect_uri = "http://prod.local"
};
try
{
var result = validator.Validate(app, request);
}
catch (AuthorizeRequestClientException ex)
{
Assert.IsTrue(ex.Error == OAuthConstants.Errors.InvalidRequest);
return;
}
Assert.Fail("No exception thrown.");
}
开发者ID:Excelsior-Charles,项目名称:Thinktecture.AuthorizationServer,代码行数:24,代码来源:Authorize_Request_Validation_General.cs
示例17: 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);
}
// parse scopes form post and substitue scopes
validatedRequest.Scopes.RemoveAll(x => !scopes.Contains(x.Name));
// store consent decision if
// checkbox was checked
// and storage is allowed
// and flow == implicit
if (validatedRequest.Application.AllowRememberConsentDecision &&
validatedRequest.ResponseType == OAuthConstants.ResponseTypes.Token &&
rememberDuration == -1)
{
var handle = StoredGrant.CreateConsentDecision(
ClaimsPrincipal.Current.GetSubject(),
validatedRequest.Client,
validatedRequest.Application,
validatedRequest.Scopes);
_handleManager.Add(handle);
Tracing.Information("Consent decision stored.");
}
// parse refresh token lifetime if
// code flow is used
// and refresh tokens are allowed
if (validatedRequest.RequestingRefreshToken &&
rememberDuration != null &&
validatedRequest.Client.Flow == OAuthFlow.Code)
{
if (rememberDuration == -1)
{
validatedRequest.RequestedRefreshTokenExpiration = DateTime.UtcNow.AddYears(50);
}
else
{
validatedRequest.RequestedRefreshTokenExpiration = DateTime.UtcNow.AddHours(rememberDuration.Value);
}
Tracing.Information("Selected refresh token lifetime in hours: " + rememberDuration);
}
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:nanderto,项目名称:Thinktecture.AuthorizationServer,代码行数:90,代码来源:AuthorizeController.cs
示例18: Validate
public ValidatedRequest Validate(Application application, AuthorizeRequest request)
{
// If the request fails due to a missing, invalid, or mismatching
// redirection URI, or if the client identifier is missing or invalid,
// the authorization server SHOULD inform the resource owner of the
// error and MUST NOT automatically redirect the user-agent to the
// invalid redirection URI.
var validatedRequest = new ValidatedRequest();
// validate request model binding
if (request == null)
{
throw new AuthorizeRequestResourceOwnerException("Invalid request parameters.");
}
validatedRequest.Application = application;
Tracing.InformationFormat("OAuth2 application: {0} ({1})",
validatedRequest.Application.Name,
validatedRequest.Application.Namespace);
validatedRequest.ShowRememberConsent = application.AllowRememberConsentDecision;
// make sure redirect uri is present
if (string.IsNullOrWhiteSpace(request.redirect_uri))
{
throw new AuthorizeRequestResourceOwnerException("Missing redirect URI");
}
// validate client
if (string.IsNullOrWhiteSpace(request.client_id))
{
throw new AuthorizeRequestResourceOwnerException("Missing client identifier");
}
var client = _clientManager.Get(request.client_id);
if (client == null)
{
throw new AuthorizeRequestResourceOwnerException("Invalid client: " + request.client_id);
}
validatedRequest.Client = client;
Tracing.InformationFormat("Client: {0} ({1})",
validatedRequest.Client.Name,
validatedRequest.Client.ClientId);
// make sure redirect_uri is a valid uri, and in case of http is over ssl
Uri redirectUri;
if (Uri.TryCreate(request.redirect_uri, UriKind.Absolute, out redirectUri))
{
if (redirectUri.Scheme == Uri.UriSchemeHttp)
{
throw new AuthorizeRequestClientException(
"Redirect URI not over SSL : " + request.redirect_uri,
new Uri(request.redirect_uri),
OAuthConstants.Errors.InvalidRequest,
string.Empty,
validatedRequest.State);
}
// make sure redirect uri is registered with client
var validUri = validatedRequest.Client.RedirectUris.Get(request.redirect_uri);
if (validUri == null)
{
throw new AuthorizeRequestResourceOwnerException("Invalid redirect URI: " + request.redirect_uri);
}
validatedRequest.RedirectUri = validUri;
Tracing.InformationFormat("Redirect URI: {0} ({1})",
validatedRequest.RedirectUri.Uri,
validatedRequest.RedirectUri.Description);
}
else
{
var message = "Invalid redirect URI: " + request.redirect_uri;
Tracing.Error(message);
throw new AuthorizeRequestResourceOwnerException("Invalid redirect URI: " + request.redirect_uri);
}
// check state
if (!string.IsNullOrWhiteSpace(request.state))
{
validatedRequest.State = request.state;
Tracing.Information("State: " + validatedRequest.State);
}
else
{
Tracing.Information("No state supplied.");
}
// validate response type
if (String.IsNullOrWhiteSpace(request.response_type))
{
throw new AuthorizeRequestClientException(
"response_type is null or empty",
new Uri(validatedRequest.RedirectUri.Uri),
OAuthConstants.Errors.InvalidRequest,
//.........这里部分代码省略.........
开发者ID:kahneraja,项目名称:Thinktecture.AuthorizationServer,代码行数:101,代码来源:AuthorizeRequestValidator.cs
注:本文中的Thinktecture.AuthorizationServer.OAuth2.AuthorizeRequest类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论