Skip to content

Instantly share code, notes, and snippets.

@sitefinitySDK
Last active December 1, 2022 13:33
function loginOpenId(sitefinity, sitefinityUrl, username, password) {
var url = sitefinityUrl + "/Sitefinity/Authenticate/OpenID/connect/token";
var data = {
username: username,
password: password,
grant_type: "password",
scope: "openid",
client_id: "testApp",
client_secret: "secret"
};
var body = "";
Object.keys(data).forEach(key => {
if (body.length) {
body += "&";
}
body += key + "=";
body += encodeURIComponent(data[key]);
});
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.addEventListener("load", () => {
if (xhr.status == 200) {
let token = JSON.parse(xhr.responseText);
let tokenObj = {
type: token.token_type,
value: token.access_token
};
sitefinity.authentication.setToken(tokenObj);
}
});
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment