// 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 Core Registry API v2. 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 {service-accounts-url}[Service Account web console].

. 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 --location --request POST '{sso-token-url}' \
 --header 'Content-Type: application/x-www-form-urlencoded' \
 --data-urlencode 'client_id=MY_SERVICE_ACCOUNT' \
 --data-urlencode 'client_secret=MY_SERVICE_ACCOUNT_SECRET' \
 --data-urlencode 'scope=email' \
 --data-urlencode 'grant_type=client_credentials'  
---- 
+
.  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 .. 
