-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAspNetCore3JwtBearerExtensions.cs
More file actions
29 lines (25 loc) · 1.23 KB
/
Copy pathAspNetCore3JwtBearerExtensions.cs
File metadata and controls
29 lines (25 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using GraphQL.AspNetCore3;
using GraphQL.AspNetCore3.JwtBearer;
using GraphQL.DI;
namespace GraphQL;
/// <summary>
/// Extension methods for adding JWT bearer authentication to a GraphQL server for WebSocket communications.
/// </summary>
public static class AspNetCore3JwtBearerExtensions
{
/// <summary>
/// Adds JWT bearer authentication to a GraphQL server for WebSocket communications.
/// </summary>
public static IGraphQLBuilder AddJwtBearerAuthentication(this IGraphQLBuilder builder)
=> builder.AddJwtBearerAuthentication(options => { });
/// <inheritdoc cref="AddJwtBearerAuthentication(IGraphQLBuilder)"/>
public static IGraphQLBuilder AddJwtBearerAuthentication(this IGraphQLBuilder builder, bool enableJwtEvents)
=> builder.AddJwtBearerAuthentication(options => options.EnableJwtEvents = enableJwtEvents);
/// <inheritdoc cref="AddJwtBearerAuthentication(IGraphQLBuilder)"/>
public static IGraphQLBuilder AddJwtBearerAuthentication(this IGraphQLBuilder builder, Action<JwtBearerAuthenticationOptions> configureOptions)
{
builder.Services.Configure(configureOptions);
builder.AddWebSocketAuthentication<JwtWebSocketAuthenticationService>();
return builder;
}
}