kind-sugar-1935
10/19/2023, 11:12 AMchilly-king-10285
10/19/2023, 11:12 AMchilly-king-10285
10/19/2023, 11:13 AMbash
ory create oauth2-client --project "$project_id" \
--name "Client Credentials Demo" \
--grant-type client_credentials \
--token-endpoint-auth-method private_key_jwt \
--jwks-uri <https://example.org/path/to/clients/public_key_set.jwks>
Then, you can use the created client to obtain an access token using the JWT Bearer profile with the following code:
javascript
const clientID = "the-client-id"
const qs = new URLSearchParams()
qs.set("grant_type", "client_credentials")
qs.set("client_id", clientID)
qs.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer")
qs.set(
"client_assertion",
createSignedJWT(
{
iss: "<https://example.org>",
sub: clientID,
aud: "<https://your-project.projects.oryapis.com>",
jti: randomUUID(),
exp: Math.floor((Date.now() + 1000 * 60 * 60) / 1000),
iat: Date.now(),
},
privateKey,
),
)
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: qs.toString(),
}
2. Body Authentication: In this mechanism, the client sends its client ID and client secret as parameters in the body of the HTTP request. You can create a client capable of using the Body Authentication mechanism with the following Ory CLI command:
bash
ory create oauth2-client --project "$project_id" \
--name "Client Credentials Demo" \
--grant-type client_credentials \
--token-endpoint-auth-method client_secret_post
Then, you can use the created client to obtain an access token using Body Authentication with the following code:
javascript
const clientID = "the-client-id"
const clientSecret = "the-secret-id"
const qs = new URLSearchParams()
qs.set("grant_type", "client_credentials")
qs.set("client_id", clientID)
qs.set("client_secret", clientSecret)
qs.set("scope", read)
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: qs.toString(),
}
fetch("<https://your-project.projects.oryapis.com/oauth2/token>", requestOptions)
.then((response) => response.json())
.then((data) => console.log(data))
3. Basic Authentication: In this mechanism, the client sends its client ID and client secret as part of the Authorization header in an HTTP request. You can create a client capable of using the Basic Authentication mechanism with the following Ory CLI command:chilly-king-10285
10/19/2023, 11:13 AMkind-sugar-1935
10/19/2023, 11:14 AM