Skip to content

Commit

Permalink
call getBTPJWT
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Dec 25, 2023
1 parent 4df2a7f commit 823b0ed
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
20 changes: 19 additions & 1 deletion app/msal-2/authPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,25 @@ function readBooks() {
getTokenPopup(tokenRequest)
.then((response) => {
callBookshop(
bookshopConfig.booksEndpoint,
bookshopConfig.booksEndpoint.method,
bookshopConfig.booksEndpoint.path,
bookshopConfig.booksEndpoint?.body,
response.accessToken,
updateUI
);
})
.catch((error) => {
console.error(error);
});
}

function getBTPJWT() {
getTokenPopup(tokenRequest)
.then((response) => {
callBookshop(
bookshopConfig.getBTPJWTEndpoint.method,
bookshopConfig.getBTPJWTEndpoint.path,
bookshopConfig.getBTPJWTEndpoint?.body,
response.accessToken,
updateUI
);
Expand Down
8 changes: 5 additions & 3 deletions app/msal-2/bookshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
* Helper function to call MS Graph API endpoint
* using the authorization bearer token scheme
*/
function callBookshop(endpoint, token, callback) {
function callBookshop(method, endpoint, body, token, callback) {
const headers = new Headers();
const bearer = `Bearer ${token}`;

headers.append("Authorization", bearer);
headers.append("Content-Type", "application/json");

const options = {
method: "GET",
headers: headers,
method,
headers,
body,
};

console.log("request made to Graph API at: " + new Date().toString());
Expand Down
7 changes: 6 additions & 1 deletion app/msal-2/bookshopConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Add here the endpoints for MS Graph API services you would like to use.
const bookshopConfig = {
booksEndpoint: "/odata/v4/catalog/Books",
booksEndpoint: { path: "/odata/v4/catalog/Books", method: "GET" },
getBTPJWTEndpoint: {
path: "/odata/v4/catalog/getBTPJWT",
method: "POST",
body: "{}",
},
};
9 changes: 9 additions & 0 deletions app/msal-2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ <h5 class="card-title" id="WelcomeMessage">
>
Read Books
</button>
<br />
<br />
<button
class="btn btn-primary"
id="getBTPJWT"
onclick="getBTPJWT()"
>
get BTP JWT
</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 823b0ed

Please sign in to comment.