public async Task ValidateAsync(ExtensionGrantValidationContext context) { var provider = context.Request.Raw.Get("provider"); if (provider.IsEmpty()) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, "invalid provider"); return; } var providerType = (ProviderType)Enum.Parse(typeof(ProviderType), provider, true); if (!Enum.IsDefined(typeof(ProviderType), providerType)) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, "invalid provider"); return; } var token = context.Request.Raw.Get("external_token"); if (token.IsEmpty()) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, "invalid external token"); return; } var userInfo = await _providers[providerType].GetUserInfoAsync(token); if (userInfo == null) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, "couldn't retrieve user info from specified provider, please make sure that access token is not expired."); return; } context.Result = await _userProcessor.ExecuteAsync(userInfo, provider); }