-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-signalrIncludes: SignalR clients and serversIncludes: SignalR clients and servers
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Building and starting a connection with accessTokenFactory
doesn't add access_token
to the query parameters. The resulting request path ends up being /{hub}/negotiate?negotiateVersion=1
. It should be /{hub}/negotiate?negotiateVersion=1&access_token=token
given the example below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/7.0.7/signalr.min.js"></script>
<!-- Using this CDN is just for repro simplicity. I'm installing @microsoft/signalr and importing in ts in my real project -->
<script>
const connection = new signalR.HubConnectionBuilder().withUrl("/notifications", {
accessTokenFactory: () => "token" // should append &access_token=token to the query string
}).build();
connection.start().then(() => console.log('started'));
</script>
</body>
</html>
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = Environment.GetEnvironmentVariable("AUTH0_AUTHORITY_URL")
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"]; // no value
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
(path.StartsWithSegments("/notifications")))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
});
Expected Behavior
Providing the accessTokenFactory should append access_token={token}
to the query params on connection.start().then(() => ...)
Steps To Reproduce
Save this html as an index.html
and open it in your browser.
connection.start().then(() => console.log('started'));
</script>
Exceptions (if any)
N/A
.NET Version
7.0.203
Anything else?
No response
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-signalrIncludes: SignalR clients and serversIncludes: SignalR clients and servers