Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bruno/api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=
47 changes: 47 additions & 0 deletions bruno/api/auth/Anonymous session flow.bru
Original file line number Diff line number Diff line change
@@ -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]);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(":"))
Expand All @@ -44,4 +44,4 @@ script:post-response {

assert {
res.status: eq 200
}
}
50 changes: 50 additions & 0 deletions bruno/api/auth/Password flow.bru
Original file line number Diff line number Diff line change
@@ -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]);
}
}
}
}
}
4 changes: 4 additions & 0 deletions bruno/api/environments/Example.bru
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down