dotnet / dotnet/aspnetcore

Blazor oidc doesn't return meaningfull error messages

Open
#55,791 4 comments 2 reactions 0 assignees View on GitHub
area-blazor enhancement feature-oidc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I use blazor with openid connect authentication.

I follow microsoft documentation and create an authentication page:

```razor
@page "/authentication/{action}"

@code {
[Parameter]
[EditorRequired]
public string? Action { get; set; }
}
```

If any error happens the authentication page displays general message without details:

"There was an error signing in."

I assume, there should be a way to get error details.

Namely, there should be a way to get error and error_description of oidc spec.

### Expected Behavior

The authentication page should display error and error_description fields

### Steps To Reproduce

Any blazor app that utilizes oidc authentication and utilize the authentication page will show the same behaviour.

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

I digged into asp.net core source to find the problem source.

The problem is in this file:

https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/Interop/AuthenticationService.ts

Specifically in the completeSignIn function (line 258):

```csharp
async completeSignIn(url: string) {
this.trace('completeSignIn', url);
const requiresLogin = await this.loginRequired(url);
const stateExists = await this.stateExists(url);
try {
const user = await this._userManager.signinCallback(url);
if (window.self !== window.top) {
return this.operationCompleted();
} else {
this.trace('completeSignIn-result', user);
return this.success(user && user.state);
}
} catch (error) {
if (requiresLogin || window.self !== window.top || !stateExists) {
return this.operationCompleted();
}

return this.error('There was an error signing in.');
}
}
```

You should just adjust the line "return this.error('There was an error signing in.');" to return error details

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.