meta {
  name: Get Exchange Token
  type: http
  seq: 3
}

post {
  url: {{logto_endpoint}}/oidc/token
  body: formUrlEncoded
  auth: none
}

body:form-urlencoded {
  grant_type: urn:ietf:params:oauth:grant-type:token-exchange
  client_id: {{logto_webapp_client_id}}
  client_secret: {{logto_webapp_client_secret}}
  resource: https://exchange.optovia.ru
  subject_token: {{personal_access_token}}
  subject_token_type: urn:logto:token-type:personal_access_token
  organization_id: {{organization_id}}
  scope: teams:member
}

script:post-response {
  if (res.body.access_token) {
    bru.setVar("access_token_exchange", res.body.access_token);
    console.log("Exchange access token saved");
  }
}
