How to use code from the authorization action in Exchange using External oauth

Hello Experts,
I am trying to do External oauth 2.0 with surveysparrow from my forge app . Facing an issue in Exchange action . In this case once the authorization is completed im getting that code in query parameter of the redirection url like this

https://id.atlassian.com/outboundAuth/finish?code=krqFcEVfajhj2uE3IUI_EJyRXowed7GNeNdwLyW3PwQ.us-east-1

So to complete the oauth process I want to use this code in the exchange action as a request body . can we able to do that ? . FYI adding Manifest here

providers:
  auth:
    - key: surveysparrow
      name: SurveySparrow
      scopes:
        - "view_contacts"
        - "view_question"
        - "manage_share"
        - "manage_survey_settings"
        - "manage_invite"
        - "view_contact_list"
        - "manage_devices"
        - "view_survey_integrations"
        - "manage_workspace"
        - "view_questions"
        - view_reputation_app_platforms
        - "view_workspace"
        - "manage_contacts"
        - "view_invite"
        - "manage_contact_list"
        - "view_user"
        - "view_employees"
        - "view_team"
        - "manage_employees"
        - "manage_user"
        - "view_employee_list"
        - "manage_audit_logs"
        - "manage_employee_list"
        - "view_360_report"
        - "view_survey"
        - "view_targets"
        - "manage_survey"
        - "manage_team"
        - "view_survey_settings"
        - "view_ticket_fields"
        - "manage_question"
        - "view_audit_logs"
        - "view_custom_property"
        - "view_ticket_comments"
        - "view_expressions"
        - "view_tickets"
        - "manage_custom_property"
        - "manage_tickets"
        - "view_theme"
        - "manage_ticket_comments"
        - "manage_survey_share"
        - "create_dashboards"
        - "view_survey_responses"
        - "view_reputation_reviews"
        - "view_webhooks"
        - "view_dashboards"
        - "manage_responses"
        - "manage_webhooks"
      clientId: 'xxxx'
      type: oauth2
      remotes:
        - surveysparrow-api
      bearerMethod:
        type: authorization-header
      actions:
        authorization:
          remote: surveysparrow-api
          path: /o/oauth/auth
          queryParameters:
            client_id: 'xxx'
            redirect_uri: 'https://id.atlassian.com/outboundAuth/finish'
            scope: 'view_contacts+view_question+manage_share+manage_survey_settings+manage_invite+view_contact_list+manage_devices+view_survey_integrations+manage_workspace+view_questions+view_reputation_app_platforms+view_workspace+manage_contacts+view_invite+manage_contact_list+view_user+view_employees+view_team+manage_employees+manage_user+view_employee_list+manage_audit_logs+manage_employee_list+view_360_report+view_survey+view_targets+manage_survey+manage_team+view_survey_settings+view_ticket_fields+manage_question+view_audit_logs+view_custom_property+view_ticket_comments+view_expressions+view_tickets+manage_custom_property+manage_tickets+view_theme+manage_ticket_comments+manage_survey_share+create_dashboards+view_survey_responses+view_reputation_reviews+view_webhooks+view_dashboards+manage_responses+manage_webhooks'
            response_type: 'code'
        exchange:
          remote: surveysparrow-api
          path: /o/oauth/token
          overrides:
            body:
              client_id: 'xxx'
              client_secret: 'xxx'
              grant_type: 'authorization_code'
              redirect_uri: 'https://id.atlassian.com/outboundAuth/finish'
              code: code
          resolvers:
            accessToken: access_token
        retrieveProfile:
          remote: proxy-url
          path: /api/server
          resolvers:
            id: id
            displayName: displayName
            avatarUrl: avatarUrl

when i try to use like this getting 422 error code (Invalid Auth code )

Some one please help me to resolve this . Thanks in advance

@BoZhang , @anyone here please help on this issue :pray:

Hi @HeisenbergBB , unfortunately this isn’t possible at the moment, the supported overrides for exchange are listed here.
You can raise a feature request here and upvote it. If there is enough interest we will look at implementing it.
As a workaround, another thing that you can do to create a proxy endpoint which you configure as the remote for the provider. Exchange requests will then hit your proxy endpoint and you can massage the request as you need (in your case, move the code from the query param to the request body) and forward it to the provider. This isn’t an ideal approach, but should unblock you in the meantime.

Hi @BoZhang ,
Thanks for the quick help . Actually by adding response_type: 'code' in authorization function fixed this issue . The response type itself handling the general oauth flow for the above case .

1 Like