Skip to content

[release/3.1] Pass access token as query string when running SignalR in the browser - #20466

Merged
wtgodbe merged 2 commits into
release/3.1from
wtgodbe/AccessToken31
Apr 14, 2020
Merged

wtgodbe merged 2 commits into
release/3.1from
wtgodbe/AccessToken31

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Apr 2, 2020 •

Copy link
Copy Markdown
Member

Resolves #18697

Description

When running in the browser, we can't use request headers. The SignalR client tries to do so anyways, which causes issues w/ Blazor Wasm. This PR detects if we're running in the browser, and sends the access token as a query string instead.

Customer Impact

Customers writing Blazor Wasm apps w/ SignalR will not see issues when adding Auth to their apps

Regression?

No

Risk

Behavior has been tested locally, but there could be obscure scenarios we've missed.

I used https://github.com/wtgodbe/scratch/tree/master/SigRBlazor/BlazorSignalRApp to validate that the token gets passed as a query string & can be pulled out and referenced by the server.

@wtgodbe wtgodbe added Servicing-consider Shiproom approval is required for the issue ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it. labels Apr 2, 2020
@ghost

ghost commented Apr 2, 2020

Copy link
Copy Markdown

Hello human! Please make sure you've included the Shiproom Template in a comment or (preferably) the PR description. Also, make sure this PR is not marked as a draft and is ready-to-merge.

@ghost ghost added the area-signalr Includes: SignalR clients and servers label Apr 2, 2020

@halter73 halter73 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original PR #20115


internal static bool IsRunningInBrowser()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what we agreed on with the BCL team?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guidance I got from @pranavkm and @anurse was that this is the pattern going forward

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we have now. I believe discussions are ongoing and we can react later if necessary. Personally I’d prefer a string like “browser” since WASM is not browser-specific, but 🤷‍♀️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string needs to be browser. Can we circle back and make sure? Last I checked we were leaning in that direction. I worry about future breaking changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranavkm @danroth27 @SteveSandersonMS What's the story here? Is there a final decision on the string to use for detecting the browser? We'd really like to get this in and right the first time before 3.1.4 closes on Tuesday.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @lewing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any idea when that'll happen? I guess we'll need to either wait, or change the string at the same time they change it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change should land before 3.2-RC. Since this change aligns with the RTM release, using BROWSER might be the correct thing to do. Again @lewing in case you think otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change it now to BROWSER. The timing should be fine (3.1.4 is shipping no earlier than 3.2 GA, by the current schedule). It's not going to fail if the string is wrong, right? It just won't light up the fixed behavior until you're running on a runtime with the updated OS platform string.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not going to fail if the string is wrong, right? It just won't light up the fixed behavior until you're running on a runtime with the updated OS platform string.

That'd be my understanding, it won't fail, it just won't do anything until the corresponding change is made. I'll make the change

if (transportType == HttpTransportType.ServerSentEvents && _isRunningInBrowser)
{
Log.ServerSentEventsNotSupportedByBrowser(_logger);
transportExceptions.Add(new TransportFailedException("ServerSentEvents", "The transport is not supported in the browser."));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? Is it because the http client isn't fetch based?

@wtgodbe wtgodbe Apr 3, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From @BrennanConroy on the other PR:

Was thinking about this over the weekend and realized we need to do something about SSE.

Right now it doesn't work because we use an HttpClient GET with "text/event-stream" Accept header. Which doesn't work in the browser, we use the EventSource API in the Typescript client to do a streaming response.

We might just have to disable SSE when running the .NET client in the browser.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @BrennanConroy tried it and it didn’t work. We can always make adjustments and reenable. Plus, we are considering deprecating SSE in general.

@leecow leecow added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 9, 2020
@leecow leecow added this to the 3.1.4 milestone Apr 9, 2020
@wtgodbe

wtgodbe commented Apr 9, 2020

Copy link
Copy Markdown
Member Author

Windows failures are #20687

@wtgodbe

wtgodbe commented Apr 10, 2020

Copy link
Copy Markdown
Member Author

@anurse should we wait on getting the 3.1 CI fixed before merging? Failures are due to #20687, which I'm working on now

@analogrelay

Copy link
Copy Markdown
Contributor

With #20736 merged, are we ready to merge this in (once the build passes)?

@wtgodbe

wtgodbe commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

With #20736 merged, are we ready to merge this in (once the build passes)?

That was my plan, just want to get a green CI first

@wtgodbe
wtgodbe merged commit 0142997 into release/3.1 Apr 14, 2020
@wtgodbe
wtgodbe deleted the wtgodbe/AccessToken31 branch April 14, 2020 19:59
@danroth27

Copy link
Copy Markdown
Member

🎉 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it. Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants