Hi Paolo,
Thanks for your response.
I tried various ways to connect using REST API initially using Google and then JWT auth.
The below scenarios are with Custom JWT Authentication.
First, I enabled ‘Custom JWT Authentication’ in ‘Authentication Providers’.
Then inside the code,
I receive the token from Google and then I use it in the following way
const app = new Realm.App({
id: "app-id",
});
const credentials = await Realm.Credentials.jwt(response.credential);
const user = await app.logIn(credentials);
alert(`Logged in with id: ${user.id}`);
I receive the ‘user’ object.
Then, I tried using the ‘user.accessToken’ in my HTTP requests in following way:
- Bearer Authentication
let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + user.accessToken});
When I use this way, I get a
UserAppDomainMismatch Error
Error:
user does not belong to app
Authentication Method:
Bearer Authentication
- jwtTokenString in Header
let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'jwtTokenString': user.accessToken});
In this case, I get below response
Access to XMLHttpRequest at ‘https://data.mongodb-api.com/app/data-ioyhu/endpoint/data/v1/action/find’ from origin ‘https://…’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
In the network access for the time being all requests are allowed.
I have one query, How come one request passes through (Bearer Auth - even though it gives an error) while other get blocked with CORS error?
Awaiting your advice.
With regards,
Kaustubh