Respect HandleResponse() and SkipHandler() calls in OnResourceMetadataRequest (#607)
This commit is contained in:
parent
3156818d66
commit
f53e0d2132
1 changed files with 125 additions and 26 deletions
|
|
@ -43,8 +43,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
|
|||
return false;
|
||||
}
|
||||
|
||||
await HandleResourceMetadataRequestAsync();
|
||||
return true;
|
||||
return await HandleResourceMetadataRequestAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -78,10 +77,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
|
|||
return absoluteUri.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the resource metadata request.
|
||||
/// </summary>
|
||||
private async Task HandleResourceMetadataRequestAsync()
|
||||
private async Task<bool> HandleResourceMetadataRequestAsync()
|
||||
{
|
||||
var resourceMetadata = Options.ResourceMetadata;
|
||||
|
||||
|
|
@ -93,6 +89,23 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
|
|||
};
|
||||
|
||||
await Options.Events.OnResourceMetadataRequest(context);
|
||||
|
||||
if (context.Result is not null)
|
||||
{
|
||||
if (context.Result.Handled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (context.Result.Skipped)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (context.Result.Failure is not null)
|
||||
{
|
||||
throw new AuthenticationFailureException("An error occurred from the OnResourceMetadataRequest event.", context.Result.Failure);
|
||||
}
|
||||
}
|
||||
|
||||
resourceMetadata = context.ResourceMetadata;
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +117,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
|
|||
}
|
||||
|
||||
await Results.Json(resourceMetadata, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ProtectedResourceMetadata))).ExecuteAsync(Context);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
Loading…
Reference in a new issue