Last active
April 11, 2022 07:20
-
-
Save Sa1Gur/8b00c7f82204066b4647e7e049a5dba4 to your computer and use it in GitHub Desktop.
k6IdentityServer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http'; | |
/** | |
* Authenticate using OAuth against IdentityServer | |
* @function | |
* @param {string} identityServerUrl - IdentityServer url to authenticate against | |
* @param {string} clientId - Generated by IdentityServer automatically | |
* @param {string} scope - Space-separated list of scopes | |
* @param {string|object} resource - Either a resource ID (as string) or an object containing username and password | |
*/ | |
export function authenticateUsingIdentityServer( | |
identityServerUrl, | |
clientId, | |
scope, | |
resource | |
) { | |
const url = `https://${identityServerUrl}/identity/connect/token`; | |
const requestBody = { | |
scope: scope, | |
grant_type: 'password', | |
username: resource.username, | |
password: resource.password, | |
client_id: clientId | |
}; | |
return http.post(url, requestBody).json(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment