Skip to content

Commit

Permalink
Create get_access_token snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Apr 1, 2021
1 parent 1a20353 commit 1fe26c6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/api/get_access_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const accessToken = (async _ => {
const loginInit = {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ "username": USERNAME, "password": PASSWORD})
};

let loginResponse = await fetch("https://engineering.purdue.edu/webqueue/webqueue2/build/api/login", loginInit);
let data = await loginResponse.json();

if (data === null){
return false;
}

if (!loginResponse.ok){
console.error(`Login failed. Got code ${loginResponse.status} (${loginResponse.statusText})`);
return false;
}

return data.access_token || false;
})();

0 comments on commit 1fe26c6

Please sign in to comment.