keycloak and kong resource - keycloak

I am using keycloak with kong openid.
I can't login when I'm not logged in, so it works. But when I define a resource /admin, I want only users with admin role to enter.
/admin --> access just admin role
/ --> access all roles
/analiyst --> access just admin and analyst role.
No matter what I did, it didn't work, I changed everything and tried.
Kong does not see my resoures, every user can enter every endpoint.
users do not log in to every page
and keycloak
realm myapp: get access token public,
kong: only konga plugin connect confidental
keycloak1
KEYCLOAK2
KEYCLOAK3

Related

Keycloak: Prevent client from logging in specific user

Is it possible in keycloak to prevent the account client from logging in a specific user? I have a user that is only supposed to log in via the admin-cli endpoints, but it is in the same realm as the account client.
You can try to remove the
default-roles-<realm-name> role
for this user. This will remove the effective roles for the account client role

Next Auth with Keycloak (separated member database)

I made a website with Next-auth.
My Next-Auth Provider is Keycloak(Openid-connect)
I want to make a separated member database to manage access permission
Example
Keycloak Server (Email) --> Next Auth Database Server (Transaction Email and Find Access Permission) --> Website Access Granted
How do I make Next Auth Database?

keycloak-js How to authenticate AND authorize users

I'm having a bit of trouble understanding how to link together authenticating and authorizing users in my frontend using Keycloak and the keycloak-js adapter.
To preface this: I know that the keycloak-js adapter requires the client to have public as the Access Type.
My main question is how can I use Keycloak authentication AND authorization via the same client. If the Access Type MUST be set to public for the keycloak-js adapter to work, then how can I restrict access to my API depending on the users permissions?
Will I need two clients for this? One for authentication and one for authorization? If so, how can I use the access token from the authentication client in the authorization client?
My current setup in Keycloak is as follows:
Realm: admin-service
Client: admin-service-api
Access Type: confidential (because I want to use authorization to restrict api requests according to permission levels)
Root URL: http://localhost:8080/
Valid Redirect URIs: http://localhost:8080/*
Roles:
admin
Users:
test-user
My authorization setup for admin-service-api is as follows:
Resources: Books Resource
Uri (these are my API endpoints):
/v1/books
/v1/books/{id}
Scopes:
books:delete
books:create
books:update
books:read
Policies:
Default Policy
Books Policy:
Realm roles:
admin (the required checkbox is not checked)
Permissions:
Default Permission
Books Resource Permission:
Resources: Books Resource
Apply Policy: Books Policy
So with this setup, I have restricted my API (which is written in GoLang) to only allow requests if the requesting user has the appropriate permissions by making a request to the Keycloak API via https://my.auth.server/auth/realms/{{realm_name}}/protocol/openid-connect/token to retrieve the users access token and a list of the users permissions.
From there I can use this access token to make requests to my API to create/read/update/delete books so long as my test-user has the admin role. If my user does not have the admin role, the user is presented with an unauthorized message (401).

Keycloak LDAP User Authentication not working

I have configured OpenLDAP with my keycloak, so that user management is taken care by LDAP. I have successfully sync the users from LDAP and I can see the user details in my List of users in Keycloak.I am using master realm only.
But when I try to generate token giving admin-cli client it gives this error.
Even the Authorization code flow it doesn't work.Tried to log in via keycloak UI it gives Invalid Credentials.
How can we use LDAP users for authentication in Keycloak ?

Keycloak autologin after registration with direct link

I have a spring boot web app with a direct registration link to keycloak.
My spring boot application.properties looks like this:
keycloak.auth-server-url=http://localhost:8888/auth<br>
keycloak.realm=myrealm<br>
keycloak.public-client=true<br>
keycloak.principal-attribute=preferred_username<br>
keycloak.security-constraints[1].authRoles[0]=user<br>
keycloak.security-constraints[1].securityCollections[0].patterns[0]=/user<br>
A click on the link redirects me to keycloak where I can sign up. After registration I should have the default realm role user and should I be redirected to the restriced path http://localhost:9999/user. But after registration I don't have the role user and so I'm redirected back from /user to keycloak login page. When I login I have the role user and can access /user. Why doesn't direct login work when I use registration link?