本文整理汇总了C#中Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext.Validated方法的典型用法代码示例。如果您正苦于以下问题:C# OAuthValidateClientAuthenticationContext.Validated方法的具体用法?C# OAuthValidateClientAuthenticationContext.Validated怎么用?C# OAuthValidateClientAuthenticationContext.Validated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext
的用法示例。
在下文中一共展示了OAuthValidateClientAuthenticationContext.Validated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例4: 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);
}
示例5: 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;
}
}
示例6: 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();
}
示例7: 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);
}
示例8: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
var clientId = string.Empty;
var clientSecret = string.Empty;
Client client = null;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (context.ClientId == null)
{
context.Validated();
return Task.FromResult<object>(null);
}
using (var _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);
}
if (client.Secret != TokenHelper.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("as:clientAllowedOrigin", client.AllowedOrigin);
context.OwinContext.Set("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());
context.Validated();
return Task.FromResult<object>(null);
}
示例9: ValidateClientAuthentication
/// <summary>
/// 第一步:客户端认证
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
string grant_type = context.Parameters[Paths.GrantType];
if (grant_type == Paths.GrantTypes.Password)
{
string username = context.Parameters[Paths.UserName];
string password = context.Parameters[Paths.Password];
//调用登录逻辑
UserViewModel user = this.Login(username, password);
if (user != null)
{
//把当前用户存入上下文
context.OwinContext.Set<UserViewModel>("loginuser", user);
bool flag = context.Validated();
}
else
{
//context.Rejected();
//context.Rejected();
//return;
throw new BusinessException("请确认用户名和密码输入正确");
}
}
else if (grant_type == Paths.GrantTypes.RefreshToken)
{
bool flag = context.Validated();
}
else
{
throw new BusinessException("refresh token error");
//context.Rejected();
//return;
}
#region 其他两种认证方式 暂时不做
//else if (grant_type == Paths.GrantTypes.ClientCredentials || grant_type == Paths.GrantTypes.AuthorizationCode)
//{
// string clientId;
// string clientSecret;
// //TryGetBasicCredentials 指Client可以按照Basic身份验证的规则提交ClientId和ClientSecret
// //TryGetFormCredentials 指Client可以把ClientId和ClientSecret放在Post请求的form表单中提交
// if (context.TryGetBasicCredentials(out clientId, out clientSecret) || context.TryGetFormCredentials(out clientId, out clientSecret))
// {
// //grant_type:client_credentials
// //暂时不支持
// context.Rejected();
// return;
// }
//}
#endregion
}
示例10: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(
OAuthValidateClientAuthenticationContext context)
{
string clientId;
string clientSecret;
context.OwinContext.Response.Headers["Access-Control-Allow-Origin"] = "*";
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (clientId != null)
{
UserManager dbContext = context.OwinContext.Get<UserManager>();
try
{
var client = await dbContext.FindAsync(clientId, clientSecret);
if (client != null)
{
// Client has been verified.
client.AuthGrant = OAuthGrant.ResourceOwner;
context.OwinContext.Set<User>("oauth:client", client);
context.Validated(clientId);
}
else
{
// Client could not be validated.
context.Rejected();
context.SetError("invalid_client Client credentials are invalid.");
}
}
catch
{
// Could not get the client through the IClientManager implementation.
context.Rejected();
context.SetError("server_error");
}
}
else
{
//for my implementation if no client id is provided use only the user/pass
context.Validated(clientId);
}
}
示例11: ValidateClientAuthentication
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
return Task.FromResult<object>(null);
}
示例12: ValidateClientAuthentication
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
await Task.FromResult<object>(null);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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();
}
}