API Connect

 View Only
Expand all | Collapse all

API Connect Native Oauth - unable to get token for AccessCode Flow

  • 1.  API Connect Native Oauth - unable to get token for AccessCode Flow

    Posted Wed September 28, 2022 01:05 PM
    Hello Team, I am trying to implement Native Oauth2 with AccessCode Flow
    Followed IBM Documentation for this. during testing I am facing problem at the time to getting token.
    Step 1: Generate Authorization Code --> I am testing with POSTMAN and getting this code via redirect url https://example.com/redirect?code=AAKZk5nLkZejcSjerECe1E1KkZoQCThxGxbBDxIapn42WjqJwm1UQaL6lKVJOagZnXT6r88M1GLLee9lMB3w-kp218Fug_IPo9iDnqJngwPuUw
    Step 2: During TOken Generation Call I am sending https://<URL>//nativeprovideoa/oauth2/token as below

    Request Headers
    User-Agent: PostmanRuntime/7.29.2
    Accept: */*
    Postman-Token: d566b1c7-f92c-4846-a7d4-bcfc73d0cda6
    Host: stest.api.fcl.crs
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 285
    Request Body
    grant_type: "authorization_code"
    client_id: "client_id"
    client_secret: "secret"
    redirect_uri: "https://example.com/redirect"
    code: "AAKZk5nLkZejcSjerECe1E1KkZoQCThxGxbBDxIapn42WjqJwm1UQaL6lKVJOagZnXT6r88M1GLLee9lMB3w-kp218Fug_IPo9iDnqJngwPuUw"

    But continuously I am getting below error:
    {"error":"TokenManager Runtime Error","error_description":"*[bdfe75e8024995301319febd7ea866e0] Input data is invalid or incomplete*"}
    I am unable to understand why this code is giving trouble. I copied the code from response of step 1.Also this error is not turning to Datapower Gateway as a result unable to find it in IBM Cloud Logs Any guidance will be helpful


    ------------------------------
    Avik Naskar
    ------------------------------


  • 2.  RE: API Connect Native Oauth - unable to get token for AccessCode Flow

    Posted Thu September 29, 2022 01:07 AM
    Dear Avik,

    What is your Gateway Type? 
    There are multiple way to check how to pass the parameters. Also please see if you have enabled OIDC

    1. Check the yaml source parameters, you will find details to pass 
    2. Open API Connect Testing in assemble , open any API secured using it, test API using test tool in API Connect, also open browser network. After every click token check new entry in network table, you will find exactly how to pass.

    ------------------------------
    Jayprakash Yadav
    ------------------------------



  • 3.  RE: API Connect Native Oauth - unable to get token for AccessCode Flow

    Posted Thu September 29, 2022 04:49 PM
    Edited by Avik Naskar Thu September 29, 2022 05:38 PM

    Thanks Jayprakash,

    Gateway Type: Datapower API Gateway.
    I tested enabling OIDC as well as disabling OIDC, no luck, same error is turning up.

    To answer your questions.
    1. YAML file doesn't give the source parameters for token generation.

    /oauth2/token:
    post:
    consumes:
    - application/x-www-form-urlencoded
    produces:
    - application/json
    summary: >-
    Endpoint for obtaining access token using Authorization code,
    Application and Password grants
    description: >-
    This endpoint allows requesting an access token following one of the
    flows below:
    - Access Code (exchange access code for an access token)
    - Client Credentials (2-legged, resource owner credentials are not obtained)
    - Resource Owner Password Credentials (2-legged, client provides resource owner name and password)
    - Refresh Token (exchange refresh token for a new access token)
    parameters:
    - name: grant_type
    in: formData
    required: true
    type: string
    enum:
    - authorization_code
    - password
    - client_credentials
    - refresh_token
    responses:
    '200':
    description: 200 OK

    2. Even if I tested through Assemble (Gateway in version 10.0.*) it is giving same error response and I checked that parameters is not an issue.
    If the parameters are not passing or incorrect values are send then it is throwing error as "invalid request" but not "
    TokenManager Runtime Error". 
    Issue resolved:
    Not sure why oauth-auto-generated-1 step is trying to generate Token.

    ------------------------------
    Avik Naskar
    ------------------------------