You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Replace `<API>` with the API endpoint you want to access. For example, `/api/identity/users/profile`.
26
26
- Replace `<token>` with the security token you generated.
27
27
28
+
## Specifying Organization Context
29
+
30
+
{{< alert type="info" title="API Tokens are User-Scoped" >}}
31
+
Layer5 Cloud API tokens are scoped to your user account, not to a specific organization. This means a single API token provides access to all organizations you are a member of. For users who belong to multiple organizations, you need to explicitly specify which organization your API requests should operate on.
32
+
33
+
This is similar to how [GitHub Personal Access Tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) work, where a single token grants access to all repositories and organizations the user has access to.
34
+
{{< /alert >}}
35
+
36
+
There are two ways to control the organization context for your API requests:
37
+
38
+
### Using the `layer5-current-orgid` Header
39
+
40
+
Include the `layer5-current-orgid` header with your organization's ID to specify the target organization for a request:
41
+
42
+
{{< tabpane >}}
43
+
{{< tab header="cURL" >}}
44
+
curl -X POST "https://cloud.layer5.io/api/pattern" \
const res = await fetch("https://cloud.layer5.io/api/pattern", {
59
+
method: "POST",
60
+
headers: {
61
+
Authorization: `Bearer ${token}`,
62
+
"layer5-current-orgid": orgId,
63
+
"Content-Type": "application/json",
64
+
},
65
+
body: JSON.stringify({
66
+
name: "my-design",
67
+
pattern_file: "...",
68
+
}),
69
+
});
70
+
const data = await res.json();
71
+
console.log(data);
72
+
}
73
+
74
+
createDesign();
75
+
76
+
{{< /tab >}}
77
+
78
+
{{< tab header="Python" >}}
79
+
80
+
import requests
81
+
import json
82
+
83
+
url = "https://cloud.layer5.io/api/pattern"
84
+
headers = {
85
+
"Authorization": "Bearer <Your-Token>",
86
+
"layer5-current-orgid": "<Your-Organization-ID>",
87
+
"Content-Type": "application/json"
88
+
}
89
+
payload = {
90
+
"name": "my-design",
91
+
"pattern_file": "..."
92
+
}
93
+
94
+
res = requests.post(url, headers=headers, data=json.dumps(payload))
95
+
print(res.json())
96
+
97
+
{{< /tab >}}
98
+
99
+
{{< /tabpane >}}
100
+
101
+
### Setting Organization and Workspace Preferences
102
+
103
+
Alternatively, you can set your default organization and workspace using the Preferences API. This sets your user preferences so that subsequent API requests will use the specified organization and workspace context:
104
+
105
+
{{< tabpane >}}
106
+
{{< tab header="cURL" >}}
107
+
# Set organization and workspace preferences
108
+
curl -X PUT "https://cloud.layer5.io/api/identity/users/preferences" \
109
+
-H "Authorization: Bearer <Your-Token>" \
110
+
-H "Content-Type: application/json" \
111
+
-d '{
112
+
"selectedOrganization": "<Your-Organization-ID>",
113
+
"selectedWorkspace": "<Your-Workspace-ID>"
114
+
}'
115
+
116
+
{{< /tab >}}
117
+
118
+
{{< tab header="JavaScript" >}}
119
+
120
+
const token = "Your-Token";
121
+
122
+
async function setPreferences() {
123
+
const res = await fetch("https://cloud.layer5.io/api/identity/users/preferences", {
Copy file name to clipboardExpand all lines: content/en/cloud/security/tokens.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,10 @@ Layer5 Cloud REST API uses [OAuth 2.0](https://oauth.net/2/) for authentication
15
15
16
16
Access tokens are opaque tokens that conform to the OAuth 2.0 framework. They contain authorization information, but not identity information. They are used to authenticate and provide authorization information to Layer5 APIs. Access tokens are associated with a user account. They have an unlimited lifetime and can be revoked at any time.
17
17
18
+
{{< alert type="info" title="API Tokens are User-Scoped, Not Organization-Scoped" >}}
19
+
Layer5 Cloud API tokens are scoped to your user account, not to a specific organization. This means a single API token provides access to all organizations you are a member of, similar to how [GitHub Personal Access Tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) work. For users who belong to multiple organizations, see [Specifying Organization Context](/cloud/reference/api-reference/#specifying-organization-context) in the REST API documentation to learn how to control which organization your API requests operate on.
20
+
{{< /alert >}}
21
+
18
22
## Creating tokens
19
23
20
24
You can create a token for your user account at any time. Tokens never expire, but can be revoked. You can also give the token a descriptive label. This label will be shown in the list of tokens on your user account's security tokens page.
0 commit comments