openshift

Curl to Openshift console to get access token


I am trying to retrieve user access token for openshift login. The way I want to achieve is through curl command where user provides his username and password and in response will get the token. I cannot use openshift python client and it has to be a GET/POST call only.


Solution

  • You need to do the below steps

    1. Export/Get the token from the curl command

    export TOKEN=$(curl -u user1:test@123 -kI 'https://myose01:8443/oauth/authorize?clientid=openshift-challenging-client&response_type=token' | grep -oP "access_token=\K[^&]*")

    1. Export/Set your endpoint

    export ENDPOINT=myose01:8443

    1. Test any of open shift rest call with above two variables

    Test sample:-

    curl -k \
        -H "Authorization: Bearer $TOKEN" \
        -H 'Accept: application/json' \
        https://$ENDPOINT/oapi/v1/projects