public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
try
{
string clientId;
string clientSecret, deviceId;
string appId = context.Parameters["applicationId"];//renamed from applicationName
string version = context.Parameters["version"];
deviceId = context.Parameters["deviceId"];//renamed from applicationName
context.OwinContext.Set("appId", appId);
ApiAppClient client;
if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (string.IsNullOrWhiteSpace(clientId))
{
context.TryGetFormCredentials(out clientId, out clientSecret);
}
if (string.IsNullOrWhiteSpace(clientId))
{
var query = context.Parameters.Where(x => x.Key == "client_id");
if (query.Any())
{
clientId = query.FirstOrDefault().Value?[0];
}
}
if (string.IsNullOrWhiteSpace(clientId))
{
//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($"Missing ClientId.");
////context.Rejected();
return;
}
POST https://example.com/token HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Host: example.com
Content-Length: 258
client_id=xxxxxxxxxxxxxxxxxxxxxx&client_secret=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&applicationId=aaaaaaaaaaaaaaaaaaaaaaaa&username=me&password=somthing&grant_type=password&deviceId=5545555&version=3.2.1.89
我对上面的OAuth进程有一个奇怪的例子,ClientId为null,而且参数为空。