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
Copy file name to clipboardExpand all lines: packages/console/src/assets/docs/guides/m2m-general/README.mdx
+73-78Lines changed: 73 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ There are two common use cases of using machine-to-machine apps in Logto:
21
21
1.**Accessing Logto Management API**: In this case, you need to assign a M2M role that include the `all` permission from the built-in Logto Management API to your M2M app.
22
22
2.**Accessing your API resource**: In this case, you need to assign M2M roles that include permissions from your API resources to your M2M app.
23
23
24
-
During the M2M app creation process, you’ll be directed to a page where you can assign machine-to-machine (M2M) roles to your applications:
24
+
During the M2M app creation process, you'll be directed to a page where you can assign machine-to-machine (M2M) roles to your applications:
@@ -42,104 +42,101 @@ And you also need to include your M2M app's credentials in the request header fo
42
42
43
43
This is achieved by including the app's credentials in the [Basic authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization#basic_authentication) form in the request `Authorization` header, where username is the App ID, and password is the App Secret.
44
44
45
-
You can find the App ID and App Secret from your M2M app's details page:
45
+
The App ID and App Secret are as follows, and you can also find them in your M2M app details page:
46
46
47
47
<ApplicationCredentials />
48
48
49
-
An example of the access token request is:
49
+
And the authentication string can be generated by encoding the app ID and app secret to Base64 format, with the fake code below:
In the following demonstration, replace `https://your.logto.endpoint` with the Logto endpoint you are targeting. For Logto Cloud, it will be `https://[your-tenant-id].logto.app`.
Logto provides a built-in “Logto Management API” resource, it’s a readonly resource with the `all` permission to access Logto Management API, you can see it from your API resource list.
74
-
The resource API indicator is in the pattern of `https://[your-tenant-id].logto.app/api`, and this will be your resource value used in the access token request body.
76
+
Logto provides a built-in "Logto Management API" resource, it's a readonly resource with the `all` permission to access Logto Management API, you can see it from your API resource list.
77
+
The resource API indicator is in the pattern of `https://[your-tenant-id].logto.app/api`, and this will be your resource value used in the access token request body.
75
78
76
79
<imgalt="Logto Management API details"src={LogtoManagementApiSrc}width="600px"style={{ borderRadius: '6px' }}/>
77
80
78
-
Before accessing Logto Management API, make sure your M2M app has been assigned with M2M roles that include the `all` permission from this built-in “Logto Management API” resource.
81
+
Before accessing Logto Management API, make sure your M2M app has been assigned with M2M roles that include the `all` permission from this built-in "Logto Management API" resource.
79
82
80
83
<InlineNotification>
81
-
Logto also provides a pre-configured “Logto Management API access” M2M role for new created tenants, which the Logto Management API resource’s all permission has already assigned to. You can use it directly without manually setting permissions. This pre-configured role can also be edited and deleted as needed.
84
+
Logto also provides a pre-configured "Logto Management API access" M2M role for new created tenants, which the Logto Management API resource's all permission has already assigned to. You can use it directly without manually setting permissions. This pre-configured role can also be edited and deleted as needed.
82
85
</InlineNotification>
83
86
84
87
Now, compose all we have and send the request:
85
88
86
89
<Tabs>
87
90
<TabItemvalue="Node.js"label="Node.js">
88
91
89
-
```js
90
-
constlogtoEndpoint='https://your.logto.endpoint'; // Replace with your Logto endpoint
For Logto Cloud users: when you’re interacting with Logto Management API, you can not use custom domain, use the default Logto endpoint `https://[your_tenant_id].logto.app/oidc/token` to grant access tokens.
134
-
</InlineNotification>
135
-
136
133
### Access token response
137
134
138
135
A successful access token response body would be like:
139
136
140
137
```json
141
138
{
142
-
"access_token": "<granted-access-token>", // Use this token to access the API resource
139
+
"access_token": "<granted-access-token>", // E.g. eyJhb...2g
143
140
"expires_in": 3600, // Token expiration in seconds
144
141
"token_type": "Bearer", // Auth type for your request when using the access token
145
142
"scope": "all"// scope `all` for Logto Management API
@@ -158,7 +155,7 @@ In your API Resource list, find the API identifier that the app needs to access.
@@ -235,34 +230,34 @@ You may notice the token response has a `token_type` field, which it's fixed to
235
230
<Tabs>
236
231
<TabItemvalue="Logto Management API"label="Interact with Logto Management API">
237
232
238
-
Using the requested access token with the built-in Logto Management API resource `https://[your-tenant-id].logto.app/api` to get all applications in Logto:
233
+
Using the requested access token with the built-in Logto Management API resource `https://[your-tenant-id].logto.app/api` to get all applications in your Logto tenant:
239
234
240
235
<Tabs>
241
236
<TabItemvalue="Node.js"label="Node.js">
242
237
243
-
```js
244
-
constlogtoEndpoint='https://your.logto.endpoint'; // Replace with your Logto endpoint
245
-
constaccessToken='eyJhb...2g'; //Access Token
238
+
<CodeclassName="language-js">
239
+
{`const logtoEndpoint = '${props.endpoint}';
240
+
const accessToken = 'eyJhb...2g'; // Your JWT access token
0 commit comments