Skip to content

Instantly share code, notes, and snippets.

@Sa1Gur
Last active April 11, 2022 07:20
Show Gist options
  • Save Sa1Gur/8b00c7f82204066b4647e7e049a5dba4 to your computer and use it in GitHub Desktop.
Save Sa1Gur/8b00c7f82204066b4647e7e049a5dba4 to your computer and use it in GitHub Desktop.
k6IdentityServer.js
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