Hi,
What's the problem now
Hi,
Yes, you need to add ConfigureCors
method to your module class.
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
.......
ConfigureCors(context, configuration);
}
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder
.WithOrigins(
configuration["App:CorsOrigins"]?
.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(o => o.Trim().RemovePostFix("/"))
.ToArray() ?? Array.Empty<string>()
)
.WithAbpExposedHeaders()
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
}
And add app.UseCors();
below UseAbpSecurityHeaders
.
....
app.UseAbpSecurityHeaders();
app.UseCors(); // add this line
....
You can try abp new Acme.BookStore -u blazor --separate-identity-server -ts "d://app-5.3.4.zip" --version 5.3.4 -dbms SqlServer -o "D:\test\456" --trust-version
hi,
I recommend you upgrade to 9.1.1.
import { ToasterService } from '@abp/ng.theme.shared';
import { HttpErrorResponse } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Public } from '@volo/abp.ng.account/public/proxy';
import { IdentityLinkLoginService, LinkLoginHandler } from '@volo/abp.ng.identity/config';
import { from, of, pipe } from 'rxjs';
import { catchError, filter, switchMap, tap } from 'rxjs/operators';
@Injectable({ providedIn: 'root' })
export class MyLinkLoginHandler {
private router = inject(Router);
private route = inject(ActivatedRoute);
private identityLinkLoginService = inject(IdentityLinkLoginService);
private toaster = inject(ToasterService);
private handleLinkLoginError = (err: HttpErrorResponse) => {
this.toaster.error(err.error?.error_description);
return of(null);
};
private listenToQueryParams() {
this.route.queryParams
.pipe(
filter(params => params.handler === 'linkLogin' && (params.linkUserId || params.token)),
switchMap(
(
params: Public.Web.Areas.Account.Controllers.Models.LinkUserLoginInfo & {
token?: string;
},
) => {
if (params.token) {
Object.entries(JSON.parse(params.token)).forEach(([key, value]: [string, string]) => {
localStorage.setItem(key, value);
});
}
return params.linkUserId
? this.linkLogin(params)
: of(null).pipe(this.pipeToNavigate());
},
),
)
.subscribe();
}
private pipeToNavigate() {
return pipe(
switchMap(() =>
from(
this.router.navigate(['.'], {
relativeTo: this.route,
queryParams: { handler: null, linkUserId: null, linkTenantId: null, token: null },
queryParamsHandling: 'merge',
}),
),
),
tap(() => location.reload()),
);
}
constructor() {
this.listenToQueryParams();
}
linkLogin(input: Public.Web.Areas.Account.Controllers.Models.LinkUserLoginInfo) {
return this.identityLinkLoginService.linkLogin(input).pipe(
catchError(this.handleLinkLoginError),
switchMap(res => {
if(res == null)
{
return of(null);
}
if (res.tenant_domain) {
const now = new Date().valueOf();
const token = {
access_token: res.access_token,
refresh_token: res.refresh_token,
access_token_stored_at: now,
expires_at: now + res.expires_in * 1000,
};
location.href = `${res.tenant_domain}?handler=linkLogin&token=${JSON.stringify(token)}`;
return of(null);
}
localStorage.setItem('access_token', res.access_token);
if (res.refresh_token) localStorage.setItem('refresh_token', res.refresh_token);
return of(null).pipe(this.pipeToNavigate());
}),
);
}
}
Hi,
It could be a problem, we will improve the error handler.
You can try replacing the LinkLoginHandler
service to fix it.
@NgModule({
declarations: [AppComponent],
......
providers: [
{ provide: LinkLoginHandler, useClass: MyLinkLoginHandler } //
],
bootstrap: [AppComponent]
})
export class AppModule {}