Ok, I've been trying to figure this out, I've read some articles but none of them provide the answer I'm looking for.
My question is: Why Task
has to return a Task whilst async Task
doesn't?
For example:
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
// Code removed for brevity.
return Task.FromResult<object>(null);
}
As you can see there, that method isn't async
, so it has to return a Task.
Now, take a look at this one:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
// Code removed for brevity...
if(user == null)
{
context.SetError("invalid_grant", "username_or_password_incorrect");
return;
}
if(!user.EmailConfirmed)
{
context.SetError("invalid_grant", "email_not_confirmed");
return;
}
// Code removed for brevity, no returns down here...
}
It uses the async
keyword, but it doesn't return a Task. Why is that?
I know this may be probably the stupidest question ever.
But I wanna know why it is like this.