Do Keycloak Clients have a Client Secret? - oauth-2.0

Does keycloak client id has a client secret? I tried to create a client in keycloak admin but I was not able to spot client secret.
Is it auto generated? Where can I get the secret?

Your client need to have the access-type set to confidential , then you will have a new tab credentials where you will see the client secret.
https://wjw465150.gitbooks.io/keycloak-documentation/content/server_admin/topics/clients/oidc/confidential.html

Client need to have the access-type set to confidential and you can see the client Secret in credentials tab

Does keycloak client id has a client secret? I tried to create a
client in keycloak admin but I was not able to spot client secret.
First, you should know that Keycloak implements OpenID Connect, which
is a simple identity layer on top of the OAuth 2.0 protocol.
According to the OAuth 2.0 protocol clients can be either confidential or public.
The main difference relates to whether or not the application is able
to hold credentials (such as a client ID and secret) securely.
Regarding the confidential clients:
Because they use a trusted backend server, confidential applications
can use grant types that require them to authenticate by specifying
their client ID and client secret when calling the Token endpoint.
Armed with this knowledge you can easily create a client that will have a client secret as follows:
OLD Keycloak UI
Create a client with "Access Type" set to confidential:
Click the Save button;
Afterwards a new tab named "Credentials" will show up :
And there you can see the client secret:
NEW Keycloak UI
Go to your realm and the Clients
Click on the button Create client
Set the clientID, and the remains fields accordingly and click next
Set the option Client authentication to ON
Click on Save
To inspect the secret go to the clients > your client > tab credentials and click on the eye
In my personal Git repo you can find a script to extract the client secret. This script calls the endpoint
GET /{realm}/clients/{id}/client-secret
from the Keycloak admin API.

In keycloak version 20, access-type does not exist an as option.
If your client to be configured does not already have authentication on, set it on and then click save.
Your client will then have a "Credentials Tab" on the top, next to "Settings", "Keys", "Roles" etc.
Click on the Credentials tab and your Client secret is found on that screen.

For me above mentioned step access-type tab not found.
What did work for me is:
Select your realm in my case "istiomesh"
Select "clients" tab in left bar
You may see two tabs "client list" and "Initial access token". Select later one and create Initial access token
4. Copy that token and use as secret

Related

How to obtain access token in webapp without login form (keycloak)

The goal is to get an access token from Keycloak to use that token for API calls.
The app should not require any login from the user, so it just need to authenticate itself.
I was planning to use client_credentials flow for that. However, client_credentials require the client to be confidential. And confidential clients have CORS issues in Keycloak.
If I switch to a public client I cannot use client_credentials flow anymore.
What is the best way to continue from here? Maybe I need to use password credentials flow and public client, because client credentials are going to be exposed anyway?
Create a new client, confidential, and activate service account on it.
You will be able to authenticate with grant_type=client_credentials using the client_id and client_secret as credentials (hence the service account, it's not a user account).
You will obtain an access token, no refresh token, and you'll simply have to reconnect again using the same credentials when the access_token will be expired.
For the permissions of this service account on the REST API check the 'scope' tab and the new 'Service Account' tab. You'll need access on some of the 'realm-managment' roles.
About creation new client application, it's not unusual to have several clients for the same real application, like you could have a bearer-only client for the API part, and a confidential one for other things. I do not know what is you CORS problems with confidential clients.
confidential clients are used by full stack applications (not front+back ones), and service accounts (B-to-B).
bearer_only is for API backs
public is only for front application (like angular, vuejs, etc) where you cannot store a client secret and the security depends only on the redirect_uri filter.

Making client secret configurable

We have a number of apps that communicate with each other. One app goes to a customer, and it has to communicate with a central server to get certain information. We use OAuth2 authentication, and we already use username and password to authenticate access to the central server app.
We hardwire an OAuth2 clientid and a client secret into the customer app so that the server app knows it is an instance of the app talking to it. Recently we have been asked to make the client ID and client secret configurable by the customer, so that each customer will have different OAuth clientid and client secret. id and secret would be generated by the server and the customer would set the id and secret on their installation of the app.
Is this normal practice
Does it add any useful security value
References to reputable publications addressing this would be especially welcome.
EDIT: We are using Resource Owner Password Flow, where username and password, as well as clientId and secret, are stored (encrypted) in the client app. The customer who installs the app gets given a username/password/clientid/clientsecret supplied to them, and that combination is always used to connect from client app to server app, whichever end user is logged in to the client app. (The id/secret/username/password combination can be changed if it is compromised, but changing it is expected to be rare.) This effectively makes the installation of the client app the resource owner. (I didn't design this)
I am afraid to say that the way your system uses the Resource Owner Password Flow is not normal practice (Resource Owner Password Flow). When client ID, client secret, username and password are hard wired in the client app, you could as well use the Client Credentials Flow.
Adding a configurable part to the hard wired authentication, poses the challenge to supply this new part to the customer in a secure way. On the other hand it gives you the possibility to revoke the authentication of a single customer in case it got compromised. Doing this in making the client ID and secret configurable is not normal practice. If you change the client app, so that the username and password are configured by the customer you would get closer to the standard Resource Owner Password Flow. This flow is deprecated but could be ok in your case (when to use).
By doing this step the resource is no longer owned by the client, but by a group of customers and customers can be excluded from this group.
Another way would be to change to the Client Credentials Flow and make the client ID and secret configurable. This way the customers clients would appear as different clients. The effect is nearly the same.
Summed up you have two sets of credentials (client ID:secret and username:password). Today both identify the client. One way or the other you could add the ability to identify the customer.
it is not considered best practice to hard code secrets into an app, the encryption of those only shifts the problem to the encryption key; there is a specification that addresses your "dynamic client" use case, called OAuth 2.0 Dynamic Client Registration https://www.rfc-editor.org/rfc/rfc7591

How do I get tokens for a Google Web application using oauth.tools?

I would like to use OAuth.tools to get an access token, refresh token, and ID token for my Web application that I've setup in Google Identity Platform? I'm unsure how to configure OAuth.tools to communicate with Google's OAuth server, and there are various flows, but I'm not sure which applies to my Web application. What should I fill in here, for instance, to make it work with OAuth.tools:
To do this, you need to:
Configure the client at Google (the screenshot above)
Setup an environment in OAuth.tools to be able communicate with Google's identity platform
Perform the code flow
First, the origins of the Web application should should be set to https://oauth.tools. The redirect URIs should be set to https://oauth.tools/callback/code.
After you create the client, take note of its client ID and secret. You'll need them later to configure OAuth.tools.
Next, in OAuth.tools, create a new environment:
In the Issuer field, enter https://accounts.google.com/ and click Refresh. This will populate all of the endpoints from the Google discovery document. You can give the environment a nice name too if you want:
Next, on the Client tab, click + New client. Then, enter the Client ID of the Google client you took note of. Set the secret as well and toggle on Code Flow:
Close that modal, and then create a new flow:
Select Code Flow:
In the environment dropdown, make sure the one you created is selected:
In the Client ID text combobox, pick the one you created in the environment. Select openid or type it and hit enter. Click the Run button:
Login at Google and consent to the app if you're prompted to.
Finally, after you get back to OAuth.tools, hit Redeem Code next to step 3:
In the result pane on the right, you'll see the access token and ID token.
If you want a refresh token as well, checkout this answer that explains more about how to obtain a refresh token from Google.

oAuth2 security issue with clinet_id and secret key : user can press inspect element and earn clinet_id and secret key

I write a rest api with yii2 and i am using oAuth2 , the problem is when user want login , client web application should send request to get token , request should contain client_id and secret_key and username and password in this case user can simply inspect element and click to network and see posted parameter to the server this means user can see client_id and secret_key.
client_id and secret_key are signature for each application and server can find out witch application use api.
how to handle this security issue?
It seems you have missed out one key element of OAuth 2.0, client type.
OAuth 2.0 defines two types of clients, public clients and confidentiatl clients.
2.1. Client Types
confidential
These are the clients which can protect a credential. They have the
full potential to use authorization code grant type, which obtain
token from backchannel request. Because they use backchannel to obtain
tokens, their credentials are never exposed to end user(via user
agent)
public
Clients which cannot protect credentials. For example SPA clients and
mobile apps comes to this category.
In your case, you seems to have a public client (user agent based application in broswer as it seems). In such case, you should set your client type to a public client. If this is not the case, you are not utilizing a proper back channel call from your web application.
Additionally, public clients which use authorization code flow can use PKCE to avoid authorization code theft attacks. Related RFC can be found from RFC7636

Using Hashicorp Vault for storage of client id and secret in OAuth2 Password Flow

I am new to Hashicorp Vault. I was hoping to secure my client id and secret for an OAuth2 Password Flow using Hashicorp Vault. Each time my backend REST API is called, it requires the client id and secret, as well as the user credentials of username and password. How would I do this in a secure way and only let my app pass this without disclosing this in my javascript client?
Thanks.
John
If I read your question correctly, you have a Javascript application that calls your own (REST) backend service. That call is secured using a client id, client secret, username ánd password. That raises a couple of issues:
client id and secret, as well as the user credentials of username and password
That seems like the wrong approach to take: an OAuth-secured resource (your REST backend service) should not require a username and password. Logging in the user is done in the authorization server.
Try starting with reading the OAuth2-spec (RFC 6749) or the DigitalOcean tutorial for a comprehensive overview.
How would I do this in a secure way and only let my app pass this without disclosing this in my javascript client?
You can't: client secrets cannot be protected in a client-controlled application because an evil client can reverse-engineer your application (or read your javascript). What you have is called a "public client", i.e. a client that cannot keep its secret confidential. In this case, you don't use client secrets. Try starting with this question or the introduction to oauth2 client types.

Resources