Send client id and secret
This commit is contained in:
parent
29cf7288fe
commit
42717b397e
|
@ -45,13 +45,15 @@ describe("oauth2 utils", () => {
|
|||
const oauthConfig = await sdk.oauth2.create({
|
||||
name: generator.guid(),
|
||||
url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`,
|
||||
clientId: "my-client",
|
||||
clientSecret: "my-secret",
|
||||
})
|
||||
|
||||
const response = await generateToken(oauthConfig.id)
|
||||
return response
|
||||
})
|
||||
|
||||
expect(response).toBe("")
|
||||
expect(response).toBe(expect.stringMatching(/^Bearer .+/))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -8,7 +8,18 @@ export async function generateToken(id: string) {
|
|||
throw new HttpError(`oAuth config ${id} count not be found`)
|
||||
}
|
||||
|
||||
const resp = await fetch(config.url, { method: "post" })
|
||||
const resp = await fetch(config.url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
grant_type: "client_credentials",
|
||||
client_id: config.clientId,
|
||||
client_secret: config.clientSecret,
|
||||
}),
|
||||
redirect: "follow",
|
||||
})
|
||||
if (resp.status !== 200) {
|
||||
throw new Error(`Error fetching oauth2 token: ${resp.statusText}`)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ export interface OAuth2Config {
|
|||
id: string
|
||||
name: string
|
||||
url: string
|
||||
clientId: string
|
||||
clientSecret: string
|
||||
}
|
||||
|
||||
export interface OAuth2Configs extends Document {
|
||||
|
|
Loading…
Reference in New Issue