meta {
  name: Get ID Token
  type: http
  seq: 1
}

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}}
  subject_token: {{personal_access_token}}
  subject_token_type: urn:logto:token-type:personal_access_token
  scope: openid profile email
}

script:post-response {
  if (res.body.id_token) {
    bru.setVar("id_token", res.body.id_token);
    console.log("ID Token saved");
  }
  if (res.body.refresh_token) {
    bru.setVar("refresh_token", res.body.refresh_token);
    console.log("New refresh_token saved");
  }
}
