How to get roles for a custom user storage provider - keycloak

I'm currently attemting to extend Keycloak by implementing a custom user storage provider. I've connected to a custom database and was able to authenticate users using it. What I would like to do is know how and which methods should I implement to get user roles into my keycloak realm via this custom provider? thanks appreciate any idea about this.

Related

How can I add roles from an external db after a user has been loggedin successfully

We want to integrate Keycloak 18 in our platform to replace a self-implemented solution in the future. The first step was to implement an own user provider to keep our existing tables where users, roles and permissions are stored. This was pretty easy. So the old and new way can co-exist for a step-by-step replacement.
Now we also want to provide integrations for other user providers, like LDAP, Kerberos etc.
Is there a way to load the roles from our external db table after a user was authenticated by a random user provider?
e.g.:
User sends auth request to keycloak
User has been successfully authenticated by the ldap user provider
lookup external db to get the roles for the username and add them to the user model
thank you for your help

How to implement a custom Social Identity Provider on Keycloak?

I am trying to integrate a legacy OAuth 2.0 provider which does not support OpenID Connect 1.0 as identity provider on Keycloak.
This legacy provider provides a xml service that returns the user details similar to userinfo.
I see that Keycloak has the concept of social providers but I can’t find any resources of how to implement and register on GUI a new one.
Here is the part of the documentation in Keycloak that is referring to this sort of providers: Identity Brokering APIs.
I also suggest you to take a look at the source code of some custom providers implemented as Keycloak extensions. That can be quite helpful.
Implementing a custom identity provider is typically not a straightforward task and there will be a lot of edge cases and unpredictable scenarios. If your Keycloak server can have access to the database of your identity provider (e.g. via a readonly view) then it would be much easier to just implement a custom UserStorageProvider that fetches users for Keycloak. All the other stuff will be handled by Keycloak itself. Then you can also have some custom mappers that fetch those user attributes and allowing you to put them inside tokens.

Keycloak authorization

Hi I'm pretty new with Keycloak and I don't understand some basic things about authorization. I have a REST API that exposes some resources and I want the users to have different roles depending on that resources. For example: I have users, cars and two roles (roleA, roleB). I want to assign roleA to userA for carA. Can I do this in Keycloak? How?
Thanks!
Yes, That can be done. This can be easily done via the admin console of KEYCLOAK.
Create a realm
Create a client in the realm for your application
Create roles (either realm roles or client roles)
Create resources
Create role based policies by selecting the relevant role
Create permissions by associating the created resources and the created policies
The question is a bit vague, but yes, you can do this in Keycloak.
Out of the box, Keycloak supports users and roles. It provides apis and UIs to manage these. If your app is configured to use Keycloak as a source of identity, you can access Keycloak user and role information in your app.
I'm not totally clear on how your "car" concept relates to users and roles, or where you want to manage it. But you have a couple of options:
Turn your app into an OAuth resource server and have Keycloak provide identity information via tokens. Do your cars business logic in your app. You'll want to read up on how OAuth works if you're not familiar with it.
It is possible to extend Keycloak to add custom domain objects, such as Car. More on how to do that here.

How to programmatically assign particular roles at user registration in Keycloak?

When a user registers with Keycloak I want to be able to assign one of a few different roles, determined by their selections at registration, but I can't see how to achieve this - any ideas?
You can't do that out of the box with Keycloak but you could implement your own Authentification provider, take a look here https://keycloak.gitbooks.io/documentation/content/server_development/topics/auth-spi.html

Amazon Cognito authenticate user with saml and get table data from DynamoDB. Swift

I am new to Amazon Web Services.
All tables are stored in DynamoDB. My query is how to manage and authenticate user ?
For Example.
Suppose assume I have username called mike and password is testmike. When I press login button using cognito (SAML) they autenticate user and if user return success message then fetch all table data from that user pool. How can we achieve this? I already read amazon developer guide I am confused How to implement in my code.
Or without SAML is this possible ?
Can anybody provide sample code here ?
Your help is really appreciated .
If you have your own user directory which supports SAML IdP then you can use SAML federation and access your DynamoDB table with Cognito identity credentials.
If you want to create user signup and signin functionality and let Cognito manage your users, you can use Cognito user pools. User data is not stored automatically in DynamoDB. If you want to store some additional data related to user, you can federate Cognito user with Cognito identity and use these credentials to write to Cognito sync or DyanamoDB.