本文整理汇总了C#中Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext类的典型用法代码示例。如果您正苦于以下问题:C# OAuthValidateClientAuthenticationContext类的具体用法?C# OAuthValidateClientAuthenticationContext怎么用?C# OAuthValidateClientAuthenticationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthValidateClientAuthenticationContext类属于Microsoft.Owin.Security.OAuth命名空间,在下文中一共展示了OAuthValidateClientAuthenticationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null)
{
context.SetError("invalid_clientId", "client_Id is not set");
return Task.FromResult<object>(null);
}
var resource = ResourceStore.FindResource(context.ClientId);
if (resource == null)
{
context.SetError("invalid_clientId", string.Format("Invalid client_id '{0}'", context.ClientId));
return Task.FromResult<object>(null);
}
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:mnasif786,项目名称:PortalAPIs,代码行数:27,代码来源:ApplicationOAuthProvidercs.cs
示例2: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId = string.Empty;
string clientSecret = string.Empty;
Client client = null;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null)
{
//Remove the comments from the below line context.SetError, and invalidate context
//if you want to force sending clientId/secrects once obtain access tokens.
context.Validated();
//context.SetError("invalid_clientId", "ClientId should be sent.");
return Task.FromResult<object>(null);
}
using (AuthRepository _repo = new AuthRepository())
{
client = _repo.FindClient(context.ClientId);
}
if (client == null)
{
context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", context.ClientId));
return Task.FromResult<object>(null);
}
if (client.ApplicationType == ApplicationTypes.NativeConfidential)
{
if (string.IsNullOrWhiteSpace(clientSecret))
{
context.SetError("invalid_clientId", "Client secret should be sent.");
return Task.FromResult<object>(null);
}
else
{
if (client.Secret != HashHelper.GetHash(clientSecret))
{
context.SetError("invalid_clientId", "Client secret is invalid.");
return Task.FromResult<object>(null);
}
}
}
if (!client.Active)
{
context.SetError("invalid_clientId", "Client is inactive.");
return Task.FromResult<object>(null);
}
context.OwinContext.Set<string>("as:clientAllowedOrigin", client.AllowedOrigin);
context.OwinContext.Set<string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:FarajiA,项目名称:AspNetIdentity.WebApi,代码行数:60,代码来源:CustomOAuthProvider.cs
示例3: ValidateClientAuthentication
/// <summary>
/// Validates the client id
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
// Gets the clientid and client secret from authenticate header
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
// try to get form values
context.TryGetFormCredentials(out clientId, out clientSecret);
}
// Validate clientid and clientsecret. You can omit validating client secret if none is provided in your request (as in sample client request above)
var validClient = true;//!string.IsNullOrWhiteSpace(clientId);
if (validClient)
{
// Need to make the client_id available for later security checks
context.OwinContext.Set<string>("as:client_id", clientId);
context.Validated();
}
else
{
context.Rejected();
}
return Task.FromResult(0);
}
开发者ID:KryptPad,项目名称:KryptPadWebsite,代码行数:36,代码来源:AccessTokenProvider.cs
示例4: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
// Note: We only support resource owner password grants, in which case there is no client_id involved
if (context.ClientId == null) context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:BerndVertommen,项目名称:EvaluationPlatform,代码行数:7,代码来源:CustomOAuthProvider.cs
示例5: ValidateClientAuthentication
/// <summary>
/// responsible for validating if the Resource server (audience) is already registered in our Authorization server by reading the client_id value from the request
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null && String.IsNullOrWhiteSpace(clientId))
{
context.SetError("invalid_clientId", "client_Id is not set");
}
else if (!context.HasError)
{
var audience = AudiencesStore.Instance.FindAudience(context.ClientId);
if (audience == null)
{
context.SetError("invalid_clientId", String.Format("Client '{0}' is not registered in the system.", context.ClientId));
}
else
{
context.OwinContext.Set("as:clientId", clientId);
context.OwinContext.Set("as:clientAllowedOrigin", audience.AllowedOrigin);
context.Validated();
}
}
return Task.FromResult<object>(null);
}
开发者ID:Fanuer,项目名称:EventCorp,代码行数:35,代码来源:CustomOAuthProvider.cs
示例6: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
await Task.FromResult<object>(null);
}
开发者ID:JuninhoRoseira,项目名称:br.com.klinderrh.social,代码行数:7,代码来源:AuthorizationServerProvider.cs
示例7: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) {
var clientId = context.Parameters["client_id"];
if (!string.IsNullOrWhiteSpace(clientId)) {
var grantType = context.Parameters["grant_type"];
var clientSecret = context.Parameters["client_secret"];
switch (grantType) {
case GrantType.Password:
case GrantType.ClientCredentials:
{
/* web application */
if (clientSecret == Application.WebApplication.ConsumerSecret) {
context.Validated(clientId);
return;
}
/* mobile application */
if (clientSecret == Application.MobileApplication.ConsumerSecret) {
context.Validated(clientId);
return;
}
}
break;
case GrantType.RefreshToken:
default:
context.Validated(clientId);
return;
}
}
context.Rejected();
}
开发者ID:cemkurtulus,项目名称:ck-oauth,代码行数:32,代码来源:AuthorizationServerProvider.cs
示例8: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
// validate client credentials
// should be stored securely (salted, hashed, iterated)
string id, secret;
if (context.TryGetBasicCredentials(out id, out secret))
{
var client = _dbContext
.ApiClients
.AsEnumerable()
.SingleOrDefault(c => c.Id.ToString() == id && c.IsBlacklisted == false);
if (client != null)
{
// need to make the client_id available for later security checks
context.OwinContext.Set("as:client_id", client.Id.ToString());
//context.OwinContext.Set("as:client_name", client.Name);
context.Validated();
return Task.FromResult<object>(null);
}
}
context.Rejected();
return Task.FromResult<object>(null);
}
开发者ID:rcrosbourne,项目名称:MyQuestionnaire,代码行数:26,代码来源:SimpleAuthorizationServerProvider.cs
示例9: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
// OAuth2 supports the notion of client authentication
// this is not used here
await TaskEx.Run(() => { context.Validated(); });
}
开发者ID:XVincentX,项目名称:SimInfo,代码行数:7,代码来源:AuthorizationServerProvider.cs
示例10: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
try
{
string clientId, clientSecret;
if (context.TryGetBasicCredentials(out clientId, out clientSecret) || context.TryGetFormCredentials(out clientId, out clientSecret))
{
if (Validator.ValidateClient(clientId, clientSecret))
{
context.Validated();
}
}
else
{
context.SetError("Invalid credentials");
context.Rejected();
}
}
catch (Exception e)
{
context.SetError("Server error");
context.Rejected();
}
}
开发者ID:rainymaple,项目名称:PCG.GOAL,代码行数:25,代码来源:GoalOAuthProvider.cs
示例11: ValidateClientAuthentication
/// <summary>
/// 验证Client Credentials[client_id与client_secret]
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//http://localhost:48339/token
//grant_type=client_credentials&client_id=irving&client_secret=123456&scope=user order
/*
grant_type 授与方式(固定为 “client_credentials”)
client_id 分配的调用oauth的应用端ID
client_secret 分配的调用oaut的应用端Secret
scope 授权权限。以空格分隔的权限列表,若不传递此参数,代表请求用户的默认权限
*/
//validate client credentials should be stored securely (salted, hashed, iterated)
string clientId;
string clientSecret;
//context.TryGetBasicCredentials(out clientId, out clientSecret);
context.TryGetFormCredentials(out clientId, out clientSecret);
//验证用户名密码
var clientValid = await _clientAuthorizationService.ValidateClientAuthorizationSecretAsync(clientId, clientSecret);
if (!clientValid)
{
//Flurl 404 问题
//context.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
//context.Rejected();
context.SetError(AbpConstants.InvalidClient, AbpConstants.InvalidClientErrorDescription);
return;
}
//need to make the client_id available for later security checks
context.OwinContext.Set<string>("as:client_id", clientId);
context.Validated(clientId);
}
开发者ID:WhitePoplar022,项目名称:App.WebAPI,代码行数:34,代码来源:ClientAuthorizationServerProvider.cs
示例12: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
//first try to get the client details from the Authorization Basic header
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
//no details in the Authorization Header so try to find matching post values
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret))
{
context.SetError("client_not_authorized", "invalid client details");
return Task.FromResult<object>(null);
}
var dataLayer = new RepoManager(new DataLayerDapper()).DataLayer;
var audienceDto = dataLayer.GetAudience(clientId);
if (audienceDto == null || !clientSecret.Equals(audienceDto.Secret))
{
context.SetError("unauthorized_client", "unauthorized client");
return Task.FromResult<object>(null);
}
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:statement1,项目名称:OwinAuthorizationServers,代码行数:30,代码来源:CustomOAuthProvider.cs
示例13: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string clientId = string.Empty;
string clientSecret = string.Empty;
string symmetricKeyAsBase64 = string.Empty;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null)
{
context.SetError("invalid_clientId", "client_Id is not set");
return Task.FromResult<object>(null);
}
var audience = AudiencesStore.FindAudience(context.ClientId);
if (audience == null)
{
context.SetError("invalid_clientId", string.Format("Invalid client_id '{0}'", context.ClientId));
return Task.FromResult<object>(null);
}
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:AdaskoTheBeAsT,项目名称:JWTAspNetWebApi,代码行数:28,代码来源:CustomOAuthProvider.cs
示例14: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
await Task.Factory.StartNew(() =>
{
context.Validated();
});
}
开发者ID:jeffward01,项目名称:ReviewApplicaiton,代码行数:7,代码来源:ReviewApplicationAuthorizationServiceProvider.cs
示例15: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//TODO Validate null property
string id, secret;
context.TryGetFormCredentials(out id, out secret);
var type = context.Parameters.Get("type");
switch (type)
{
case "admin":
if (id == null) id = context.Parameters.Get("Username") + "_SysAdmin";
context.Validated();
break;
case "app":
if (secret != null) context.Validated();
break;
default:
if (id != null) context.Validated();
type = string.Empty;
break;
}
context.OwinContext.Set<string>("as:client_id", id);
context.OwinContext.Set<string>("as:client_secret", secret);
context.OwinContext.Set<string>("as:type", type);
}
开发者ID:hoangvv1409,项目名称:codebase,代码行数:26,代码来源:AuthorizationServerProvider.cs
示例16: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(
OAuthValidateClientAuthenticationContext context)
{
// This call is required...
// but we're not using client authentication, so validate and move on...
await Task.FromResult(context.Validated());
}
开发者ID:tbmihailov,项目名称:light-nlp,代码行数:7,代码来源:ApplicationOAuthServerProvider.cs
示例17: ValidateClientAuthentication
/// <summary>
/// 第一步:客户端认证
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string grant_type = context.Parameters[Constant.GrantTypes.GrantType];
if (grant_type == Constant.GrantTypes.Password)
{
string username = context.Parameters[Constant.GrantTypes.UserName];
string password = context.Parameters[Constant.GrantTypes.Password];
//TODO 调用登录逻辑
bool loginFlag = true;
if (loginFlag)
{
//把当前用户存入上下文
context.OwinContext.Set<string>("loginuser", username);
bool flag = context.Validated();
}
else
{
context.Rejected();
return;
}
}
else if (grant_type == Constant.GrantTypes.RefreshToken)
{
bool flag = context.Validated();
}
else
{
context.Rejected();
return;
}
}
开发者ID:doscanner,项目名称:GF,代码行数:38,代码来源:OAuth2AuthorizationServerProvider.cs
示例18: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
try
{
var username = context.Parameters["username"];
var password = context.Parameters["password"];
if (identityService.AuthenticateUser(username, password))
{
context.OwinContext.Set("securityApi:username", username);
context.Validated();
}
else
{
context.SetError("Invalid credentials");
context.Rejected();
}
}
catch(Exception exception)
{
context.SetError(exception.Message);
context.Rejected();
}
return Task.FromResult(0);
}
开发者ID:QuinntyneBrown,项目名称:wedding-bidders,代码行数:25,代码来源:OAuthProvider.cs
示例19: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string AuthorizeSecretKey = context.Parameters["authorizeSecretKey"];
if (AuthorizeSecretKey != AValues.AuthorizeSecretKey)
{
context.SetError("invalid_clientId", string.Format("SecretKey '{0}' is not true.", AuthorizeSecretKey));
return Task.FromResult<object>(null);
}
string clientId = string.Empty;
string clientSecret = string.Empty;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null)
{
context.Validated();
return Task.FromResult<object>(null);
}
UserViewModel user = RedisHelp.GetLoginUserCache(int.Parse(context.ClientId));
if (user == null)
{
context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", context.ClientId));
return Task.FromResult<object>(null);
}
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:a526757124,项目名称:YouTravelProject,代码行数:32,代码来源:ApplicationAuthorizationServerProvider.cs
示例20: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
return Task.FromResult<object>(null);
}
开发者ID:heskew-riotapps,项目名称:RampedUp,代码行数:7,代码来源:ApplicationOAuthProvider.cs
注:本文中的Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论