Hi developers, thanks to you I was able to integrate my FastAPI with Auth0.
But now I have come up with a different issue.
I have used the sample template provided by Auth0 for my FastAPI and Angular Integration to test it. But when I used it in my FastAPI and Angular code it is throwing
Access to XMLHttpRequest at āhttp://localhost:6060/robots/ā from origin āhttp://localhost:4040ā has been blocked by CORS policy: No āAccess-Control-Allow-Originā header is present on the requested resource
GET http://localhost:6060/robots/ net::ERR_FAILED 500 (Internal Server Error)
I tried to log it then I found this
Here is a Sample code of my FastAPI and Angular.
app.module.ts
imports: [
....
AuthModule.forRoot({
...environment.auth0,
httpInterceptor: {
allowedList: [`${environment.api.serverUrl}/robots/`]
},
}),
.....
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: AuthHttpInterceptor,
multi: true,
},
],
environment.ts
export const environment = {
production: false,
auth0: {
domain: 'xxx',
clientId: 'xxx',
authorizationParams: {
audience: 'https://hello-world.example.com',
redirect_uri: 'http://localhost:4040',
},
errorPath: '',
},
api: {
serverUrl: 'http://localhost:6060',
},
};
robot.service.ts
getAllRobotsRestricted = (): Observable<ApiResponseModel> => {
const config: RequestConfigModel = {
url: `${env.api.serverUrl}/robots/`,
method: 'GET',
headers: {
'content-type': 'application/json',
},
};
return this.externalAuth0Service.callExternalApi(config).pipe(
mergeMap((response) => {
const { data, error } = response;
return of({
data: data ? (data as RobotsModel) : null,
error,
});
})
);
}
external api
callExternalApi = (config: RequestConfigModel): Observable<ApiResponseModel> => {
return this.http
.request<unknown>(config.method, config.url, config.headers)
.pipe(
mergeMap((data) => {
return of({
data: data,
error: null,
});
}),
catchError((err) => {
if (err.error && err.status) {
return of({
data: null,
error: err.error,
});
}
return of({
data: null,
error: {
message: err.message,
},
});
})
);
};
So, can you help me with this?