Bootstrap FreeKB - OpenShift - Resolve "You must obtain an API token"
OpenShift - Resolve "You must obtain an API token"

Updated:   |  OpenShift articles

Let's say the following is being displayed when attempting to sign into OpenShift using the oc login command.

~]# oc login
You must obtain an API token by visiting https://oauth-openshift.apps.lab.op.example.com/oauth/token/request

 

Before version 4.7 of OpenShift, the oc login command could be used without the -u or --username option. Starting with version 4.7, if the -u or --username option is not include, "you must obtain an API token" will be returned (see https://access.redhat.com/solutions/6008921).

You should be able to sign in by including the -u or --username option on the command line.

oc login --username john.doe

 

Or, as the message implies, you can go to the URL (https://oauth-openshift.apps.lab.op.example.com/oauth/token/request in this example) and you should be prompted to log into the OpenShift web console. If you are able to sign in, select Display Token and something like this should be displayed. Using this command, you can sign into OpenShift on the command line.

The oc config view or oc get apiserver commands can be used to display the API Server URL (api.openshift.example.com in this example).

oc login --token=abc123 --server=https://api.openshift.example.com:6443

 

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The following options can be used to display a users token.

  • In the users /home/your_username/.kube/config file | using the oc config view command

The whoami --show-token=true command can be used to display a users token.

~]# oc whoami --show-token=true
k8QzC9ZVo9Up7Ov2jn2Qm1bexp77Zy_haKrLdp0t1FR

 

Or, you can view your users /home/your_username/.kube/config file.

~]$ oc config view
apiVersion: v1
clusters:
- cluster:
    server: https://api.openshift.example.com:6443
contexts:
- context:
    cluster: api-openshift-example-com:6443
    namespace: default
    user: john.doe/api-openshift-example-com:6443
  name: default/api-openshift-example-com:6443/john.doe
current-context: default/api-openshift-example-com:6443/john.doe
kind: Config
preferences: {}
users:
- name: john.doe
  user:
    token: sha256~83miYt8vIEHeP6CDaTKRy2SUruoo-TuVxdYToGQQOqo

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 300e58 in the box below so that we can be sure you are a human.