graphql-dotnet / graphql-dotnet/server
Refactor IWebSocketAuthenticationService
- Dominant language
- C#
- Stars
- 604
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
Suggest changing method `AuthenticateAsync` to have an `AuthenticationRequest` class that includes `AuthenticationSchemes`, as follows:
```cs
///
/// Authenticates an incoming GraphQL over WebSockets request with the
/// connection initialization message. A typical implementation will
/// set the property after reading the
/// authorization token. This service must be registered as a singleton
/// in the dependency injection framework.
///
public interface IWebSocketAuthenticationService
{
///
/// Authenticates an incoming GraphQL over WebSockets request with the connection initialization message. The implementation should
/// set the .Connection.HttpContext.User
/// property after validating the provided credentials.
///
/// After calling this method to authenticate the request, the infrastructure will authorize the incoming request via the
/// , and
/// properties.
///
Task AuthenticateAsync(AuthenticationRequest authenticationRequest);
}
///
/// Represents an authentication request within the GraphQL ASP.NET Core WebSocket context.
///
public class AuthenticationRequest
{
///
/// Gets the WebSocket connection associated with the authentication request.
///
///
/// An instance of representing the active WebSocket connection.
///
public IWebSocketConnection Connection { get; }
///
/// Gets the subprotocol used for the WebSocket communication.
///
///
/// A specifying the subprotocol negotiated for the WebSocket connection.
///
public string SubProtocol { get; }
///
/// Gets the operation message containing details of the authentication operation.
///
///
/// An instance of that encapsulates the specifics of the authentication request.
///
public OperationMessage OperationMessage { get; }
///
/// Gets a list of the authentication schemes the authentication requirements are evaluated against.
/// When no schemes are specified, the default authentication scheme is used.
///
public IEnumerable AuthenticationSchemes { get; }
///
/// Initializes a new instance of the class.
///
public AuthenticationRequest(IWebSocketConnection connection, string subProtocol, OperationMessage operationMessage, IEnumerable authenticationSchemes)
{
Connection = connection;
SubProtocol = subProtocol;
OperationMessage = operationMessage;
AuthenticationSchemes = authenticationSchemes;
}
}
```
This allows for the authentication handler to attempt each scheme specified by the middleware options.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.