I have an app on MERN stack in which react app runs on port 3000 while nodejs app runs on 3001 in development environment .
I want to integrate Keycloak in app.I started Keycloak instance and created Realm named MERN in which i created two clients one is react which is public client and other is node which is bearer-only client .
I created one user also
I integrated the keycloak on react with react keycloak client configuration and got access token and passed it to Authorization Bearer on backend.
I configured the NodeJs app with node keycloak client ..
keycloak provides method keycloak.protect() to protect Apis which is not working it always gives Access Denied.
There is another method in keycloak getAccount which takes bearer token parameter and returns account in promise object.
I extracted the token from Authorization header and passed it to getAccount which returned account.
For key cloak configuration i download it from installation tab in client and haven't done any tweak just copy pasted code from keycloak nodeJS docs.
So i am not feeling any need to write code or configuration here.
For testing you can generate app from express-cli and create-react-app.
For reactJs i used library called keycloak-js and for nodeJs i used keycloak-connect.
Question is why keycloak.protect() is not working??
If anyone knows answere please tell me.
Related
I'm trying to create a micro-service on Node to send requests on the Google Compute API via POST (for example here). This micro-service will be hosted on a App Engine application.
If I understand the documentation, I need to generate a JWT token before (with the google-auth-library) and send that token with the request.
I set up the env variable GOOGLE_APPLICATION_CREDENTIALS with the JSON file path of the Service Account used by the App Engine application on my debugger (to get the same authorization on my dev env).
But I can't reproduce the sample hosted on Github gave by the Google Documentation. I get error UnhandledPromiseRejectionWarning: ReferenceError: require is not defined because I'm using Node14 with "type": "module" on the package.json.
I searched but I found no solution on this. Do you have some hint ? Maybe I need to use a different code to generate JWT token or to authentificate these POST requests ?
Thank you
i am trying to integrate keyCloak in my application, i have created a Realm name "my-app" and added 2 clients
frontend (accessType -public)
backend (accessType - bearer-only)
I want to use the access token (returned from frontend client) to authenticate backend APIs.
i want to achieve same thing explained in this tutorial by making use of Roles, Client Scopes and mappers but not working for me
https://medium.com/devops-dudes/secure-front-end-react-js-and-back-end-node-js-express-rest-api-with-keycloak-daf159f0a94e
i made a mistake in configuration,
on frontend side i made url for auth server "http://127.0.0.1:8080/auth" and on Server side it was "http://localhost:8080/auth", else everything was correct
I'm using Node/Angular for creating my new web app. now that I'm near to deploy it, I have to make sure it is properly secured and only my angular app can expose to the api.
So is there any tutorial or something to follow to setup CORS, signature, header token, IP Whitelist.
EDIT: I'm not talking about authentication. I mean hiding my endpoints and accepting only from my angular and flutter app
I am trying to authenticate to a server from my React-Native app using Azure AD.
Now, I don't understand what is a redirect URI and I don't understand where should I put my server's URL in Azure and what URL should I call from my React-Native app.
Documentation for it is quite confusing.
I don't understand what is a redirect URI
For React-Native app, the redirect_url is optional. Refer to this document for more details.
An url that ADLoginView will be redirect when login success, this property is optional.
I don't understand where should I put my server's URL in Azure and
what URL should I call from my React-Native app.
You needn't put your server's url in Azure.But you need to add authentication to your server. Then you can call your server api as normal, but with the Authorization header. This sample will help you to understand better though it is using aspnetcore.
You need to create register two applications in Azure portal. Client app and server app. You will get the access token via your native app and then use it to access your server app.
I am using Angular4 app for UI and I have a separate Node+Express app which handles rest api calls.
Angular app runs on a different port. and express app runs on a different port.
I try to use express-session framework on the server(express)app.
I use Microsoft ADAL services to authenticate the user. After successful authentication my approach was to make a rest api call from angular app to express server app by passing userEmail and set userEmail variable to req.session.userEmail. I expect the session to be available when a different route is being called to check if the session is available, but the session variable is always showing up as undefined.
What is the best solution here? My goal is to have a session management and prevent responding to unauthorized requests on the server side rest api calls.