Chapter 2. Configuring Authentication with Insights APIs
You can use either of two methods to authenticate to Red Hat Insights APIs:
- Token-based service accounts, or
- Certificate-based authentication
The Red Hat Insights API cheat sheet PDF contains step-by-step instructions to authenticate using either method. To download the cheat sheet, navigate to API Cheat sheet.
You must have login access to developers.redhat.com to access the API cheat sheet.
2.1. Obtaining access tokens Copy linkLink copied to clipboard!
Both authentication methods require access tokens. To obtain an access token, you can:
- Configure service account access from the Hybrid Cloud Console, and then use the client ID and client secret to generate the token, or
- Generate an offline access token from the Red Hat API Tokens page
2.2. Configuring service account access Copy linkLink copied to clipboard!
Procedure
- From the Red Hat Hybrid Cloud Console, Click the Settings icon and select Service Accounts.
- Click Create service account to set up the account.
- Enter a Service account name and a Short description, and click Create. The Red Hat Hybrid Cloud Console creates the service account and displays the unique Client ID and Client secret for the account.
Copy the generated Client ID and Client secret values to a secure location. You need to specify these credentials when configuring a connection to a service.
ImportantThe Client secret displays only once, so ensure that you have successfully and securely saved the copied credentials before closing the credentials window.
- After you save the Client ID and secret to a secure location, select the confirmation check box in the credentials window and close the window. The service account and its Client ID appear on the Service Accounts page.
Add the service account to the applicable User Access Groups.
NoteService accounts do not inherit permissions from Default access groups, so you must place them in a User Group to grant them access permissions.
At the command line, use a
curl
command with Red Hat single sign-on (SSO) to generate an access token. Use the service account credentials that you generated in place of<client_id>
and<client_secret>
.curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openidconnect/token -d "grant_type=client_credentials" -d "scope=api.console" -d client_id=<client_id> -d client_secret=<client_secret>
curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openidconnect/token -d "grant_type=client_credentials" -d "scope=api.console" -d client_id=<client_id> -d client_secret=<client_secret>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor more information about Red Hat SSO and generating access tokens, see Transition of Red Hat Hybrid Cloud Console APIs from basic authentication to token-based authentication via service accounts.
Red Hat Single Sign-On (SSO) responds with a JSON object containing an access token. You can use this access token to make authenticated requests to APIs. To make a request, include the access token generated in the previous step in an Authorization: Bearer HTTP header in your request. Substitute the access token for
<access_token>
.Authorization: Bearer <access_token>
Authorization: Bearer <access_token>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
- For more information about User Access and User Access Groups, see User Access Groups.
- Transition of Red Hat Hybrid Cloud Console APIs from basic authentication to token-based authentication via service accounts
2.3. Generating an offline access token Copy linkLink copied to clipboard!
Procedure
Log in to the Red Hat Customer Portal with your username and password.
NoteYou can no longer log in to your Red Hat account with your email unless your email is your Red Hat login. For more information, see Finding your Red Hat login.
- Navigate to the Red Hat API Tokens page.
- Click Generate Token to generate an offline token.
At the command line, use a
curl
command to generate an access token. Use the offline token that you generated in place of<offline_token>
.curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openidconnect/token -d grant_type=refresh_token -d client_id=rhsm-api -d refresh_token=<offline_token>
curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openidconnect/token -d grant_type=refresh_token -d client_id=rhsm-api -d refresh_token=<offline_token>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Copy the generated access token and save it in a secure location. You can use this access token to make authenticated requests to APIs.
To make a request, include the access token in an
Authorization: Bearer
HTTP header in your API call. Substitute the access token for<access_token>
.Authorization: Bearer <access_token>
Authorization: Bearer <access_token>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Save the token. The Red Hat API Tokens page displays each token only once, and does not store tokens. Offline access tokens generated from the Red Hat API Tokens page expire after 30 days of inactivity.
Additional resources
- For step-by-step instructions to migrate your API access to use token-based service accounts, see Transition of Red Hat Hybrid Cloud Console APIs from basic authentication to token-based authentication via service accounts.
- For more information about service accounts, see Creating and managing service accounts.