Skip to content

Commit

Permalink
WIP: Get OAuth2SAMLBearerAssertion
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Dec 18, 2023
1 parent 8f94936 commit 7c6ffe3
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 1 deletion.
200 changes: 200 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"dependencies": {
"@cap-js-community/odata-v2-adapter": "^1.11.12",
"@sap-cloud-sdk/http-client": "^3.9.0",
"@sap-cloud-sdk/resilience": "^3.9.0",
"@sap/audit-logging": "^5.8.2",
"@sap/cds": "^7.5.0",
Expand Down Expand Up @@ -52,6 +53,11 @@
"cov2ap": {
"plugin": true
},
"log": {
"levels": {
"catalog-service": "debug"
}
},
"requires": {
"db": {
"kind": "sqlite",
Expand Down
3 changes: 2 additions & 1 deletion srv/catalog-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ service CatalogService @(requires: 'authenticated-user') {
@readonly
entity Products as projection on external.SEPMRA_C_PD_Product;

action readSAPLogonTicket() returns String;
action getOAuth2SAMLBearerAssertion() returns String;
action readSAPLogonTicket() returns String;
}
16 changes: 16 additions & 0 deletions srv/catalog-service.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
const cds = require("@sap/cds");
const LOG = cds.log("catalog-service");

function getAuthToken(req) {
const authHeader = req._.req.headers["authorization"];
const token = authHeader.substring(7);
return token;
}

module.exports = async function (srv) {
const biscuitService = await cds.connect.to("biscuit");
const productService = await cds.connect.to("SEPMRA_PROD_MAN");

srv.on("READ", "Products", async (req) => {
const token = getAuthToken(req);
LOG.debug("Token: " + token);
return productService.run(req.query);
});

srv.on("getOAuth2SAMLBearerAssertion", async (req) => {
const token = getAuthToken(req);
LOG.debug("Token: " + token);
});

srv.on("readSAPLogonTicket", async (req) => {
// const biscuitServiceTransaction = biscuitService.transaction(req)
// Results in:
Expand Down
8 changes: 8 additions & 0 deletions test/catalog.http
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ GET http://localhost:6420/odata/v4/catalog/Books
Authorization: Bearer {{$dotenv token}}
### Read Books as Authenticated User
GET http://localhost:6420/odata/v4/catalog/Products
?$filter=IsActiveEntity eq true
&$top=10
Authorization: Bearer {{$dotenv token}}
###
POST http://localhost:6420/odata/v4/catalog/getOAuth2SAMLBearerAssertion
Authorization: Bearer {{$dotenv token}}
Content-Type: application/json

{}
### Read SAP Logon Ticket
# @name readSAPLogonTicket
POST http://localhost:6420/odata/v4/catalog/readSAPLogonTicket
Expand Down

0 comments on commit 7c6ffe3

Please sign in to comment.