// Metadata created by nebel
// ParentAssemblies: assemblies/getting-started/as_managing-registry-artifacts-api.adoc

[id="creating-access-token-for-registry-rest-api_{context}"]
= Creating an access token for {registry} REST API commands

[role="_abstract"]
This section shows a curl-based example of how to create an OAuth Bearer access token for use with the {registry} core REST API. You can do this using the OpenShift Application Services authentication server and your service account credentials.

.Prerequisites

ifdef::apicurio-registry,rh-service-registry[]
* {registry} is installed and running in your environment
endif::[]
ifdef::rh-openshift-sr[]
* You have access to the {registry} web console
endif::[]

.Procedure

. Create your service account using the web console:
+ 
https://console.redhat.com/application-services/service-accounts

. Copy the generated *Client ID* and *Client secret* credentials to a secure location. To reset your service account credentials, click the options menu on the right (three vertical dots), and select *Reset credentials*.

. Create an OAuth Bearer token using your service account client ID and client secret:  
+
[source,bash, subs="+quotes,attributes"]
----
$ curl -X POST \
  -d "grant_type=client_credentials&client_id=MY-CLIENT-ID&client_secret=MY-CLIENT-SECRET" \ 
  {sso-token-url}
---- 
+
.  Copy the contents of the access token generated in the response to a secure location:
+
[source,bash]
----
{"access_token":"eyJhbG...a3BQ",...}
----

. Set an `ACCESS_TOKEN` environment variable to the contents of the generated access token:
+
[source,bash]
----
export ACCESS_TOKEN=VALUE
----
+ 
In the example access token shown in the previous step, the `VALUE` is `eyJhbG...a3BQ`. 

//[role="_additional-resources"]
//.Additional resources
//* For more detail, see .. 
