diff --git a/bruno/api/.env.sample b/bruno/api/.env.sample index 8e2781626..ae4b32459 100644 --- a/bruno/api/.env.sample +++ b/bruno/api/.env.sample @@ -4,4 +4,4 @@ CTP_API_URL=https://api.europe-west1.gcp.commercetools.com CTP_AUTH_URL=https://auth.europe-west1.gcp.commercetools.com CTP_PROJECT_KEY= CTP_USERNAME= -CTP_USER_PWD= +CTP_USER_PWD= \ No newline at end of file diff --git a/bruno/api/auth/Anonymous session flow.bru b/bruno/api/auth/Anonymous session flow.bru new file mode 100644 index 000000000..9be9be721 --- /dev/null +++ b/bruno/api/auth/Anonymous session flow.bru @@ -0,0 +1,47 @@ +meta { + name: Anonymous session flow + type: http + seq: 3 +} + +post { + url: {{authUrl}}/oauth/{{project-key}}/anonymous/token + body: formUrlEncoded + auth: basic +} + +auth:basic { + username: {{ctp_client_id}} + password: {{ctp_client_secret}} +} + +body:form-urlencoded { + grant_type: client_credentials +} + +assert { + res.status: eq 200 +} + +script:post-response { + if(res.status == 200) { + var data = res.body; + if(data.access_token){ + bru.setEnvVar("ctp_access_token", data.access_token, true); + } + + if (data.scope) { + parts = data.scope.split(" "); + parts = parts.filter(scope => scope.includes(":")).map(scope => scope.split(":")) + if (parts.length > 0) { + scopeParts = parts[0]; + bru.setEnvVar("project-key", scopeParts[1]); + parts = parts.filter(scope => scope.length >= 3) + if (parts.length > 0) { + scopeParts = parts[0]; + bru.setEnvVar("store-key", scopeParts[2]); + } + } + } + } +} diff --git a/bruno/api/auth/clientCredentials.bru b/bruno/api/auth/Client credentials.bru similarity index 99% rename from bruno/api/auth/clientCredentials.bru rename to bruno/api/auth/Client credentials.bru index c3e30eee8..c46d71ef5 100644 --- a/bruno/api/auth/clientCredentials.bru +++ b/bruno/api/auth/Client credentials.bru @@ -25,7 +25,7 @@ script:post-response { if(data.access_token){ bru.setEnvVar("ctp_access_token", data.access_token, true); } - + if (data.scope) { parts = data.scope.split(" "); parts = parts.filter(scope => scope.includes(":")).map(scope => scope.split(":")) @@ -44,4 +44,4 @@ script:post-response { assert { res.status: eq 200 -} +} \ No newline at end of file diff --git a/bruno/api/auth/Password flow.bru b/bruno/api/auth/Password flow.bru new file mode 100644 index 000000000..c90cbe9a2 --- /dev/null +++ b/bruno/api/auth/Password flow.bru @@ -0,0 +1,50 @@ +meta { + name: Password flow + type: http + seq: 2 +} + +post { + url: {{authUrl}}/oauth/{{project-key}}/customers/token + body: formUrlEncoded + auth: basic +} + +auth:basic { + username: {{ctp_client_id}} + password: {{ctp_client_secret}} +} + +body:form-urlencoded { + grant_type: password + username: {{username}} + password: {{password}} + scope: manage_my_profile:{{project-key}} manage_my_orders:{{project-key}} +} + +assert { + res.status: eq 200 +} + +script:post-response { + if(res.status == 200) { + var data = res.body; + if(data.access_token){ + bru.setEnvVar("ctp_access_token", data.access_token, true); + } + + if (data.scope) { + parts = data.scope.split(" "); + parts = parts.filter(scope => scope.includes(":")).map(scope => scope.split(":")) + if (parts.length > 0) { + scopeParts = parts[0]; + bru.setEnvVar("project-key", scopeParts[1]); + parts = parts.filter(scope => scope.length >= 3) + if (parts.length > 0) { + scopeParts = parts[0]; + bru.setEnvVar("store-key", scopeParts[2]); + } + } + } + } +} diff --git a/bruno/api/environments/Example.bru b/bruno/api/environments/Example.bru index acad05d95..5721d49ff 100644 --- a/bruno/api/environments/Example.bru +++ b/bruno/api/environments/Example.bru @@ -2,6 +2,10 @@ vars { authUrl: https://auth.europe-west1.gcp.commercetools.com apiUrl: https://api.europe-west1.gcp.commercetools.com project-key: + ctp_client_id: + ctp_client_secret: + username: + password: } vars:secret [ ctp_client_id,