0

Magento Rest API to fetch admin token credentials to use tokens for other REST APIs as Authorization Bearer.

From Magento 2.4+, the Two Factor Authentication Module is available for security reasons.

generate Admin Token by REST API and you will face an error in a response like below, You have authenticated Google 2FA for security reasons.

{
    "message": "Please use the 2fa provider-specific endpoints to obtain a token.",
    "parameters": {
        "active_providers": [
            "google"
        ]
    }
}

1 Answer 1

0

Generate an admin access token in an alternative way,

Action: POST

URL: <BASE_URL>/rest/V1/tfa/provider/google/authenticate (Replace your actual URL with BASE_URL)

Body:

  {
        "username":"rakesh", 
        "password":"MyPassword", 
        "otp":"<SIX_DIGIT_OTP_CODE_FROM_GOOGLE_AUTHENICATOR_APP>"
  }

In the Payload, You need to pass your admin username/password with the respective field.

  • username Your Magento Admin user

  • password Your Magento Admin password

  • otp value will be a six-digit code from the Google Authenticator Mobile Apps.

Response Example:

eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjU1LCJ1dHlwaWQiOjIsImlhdCI6MTY5Mjc0NzQzNywiZXhwIjoxNjkyNzUxMDM3fQ.jJXT9DAjRS4y4Q2j4xZt16JYgs7lClO94uNu8Calgfw

The Response comes from the TFA provider REST API will be used to other APIs with Header.

Authorization Bearer <ACCESS_TOKEN> While Replace ACCESS_TOKEN from the response string value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.