cancel
Showing results for 
Search instead for 
Did you mean: 

How to use SAP Passport at UI Level in CAP Model

former_member686997
Discoverer
0 Kudos
616

How to use SAP Passport for CAP model at UI level so that it is added to header of all service call.

I was following this document =SAP Passport

gregorw
Active Contributor
0 Kudos

Your Link is pointing to an SAP internal resource. This is a public forum. Please check if you can provide an external link.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member686997
Discoverer
0 Kudos

1, In src/index.js

const libepp = require('@sap/sapdsrpassport');
const Tools = require ('@sap/sapdsrpassport/dist/util/Tools')
const CompTypes = require ('@sap/sapdsrpassport/dist/model/ComponentTypes')
const TFlags = require ('@sap/sapdsrpassport/dist/model/TraceFlags')
let epp = new libepp.DsrPassport();

// Step 1: Create a basic DsrPassport
epp.createV3Passport(
    TFlags.TraceFlags.LOW,                  // (NONE|LOW|MEDIUM|HIGH) Use LOW for just correlation
    "DemoComponent_1",                      // Passport Creator ComponentName
    0,                                      // Service: 0 for "undefined"
    "<dummy>",                              // 
    "action",                               //
    11,                                     // ActionType: 11 denotes HTTP Request
    "DemoComponent_1",                      // Previous Component PreviousComponentName
    Tools.Tools.createGUID(16),    // TransactionID 
    "   ",                                  // In case of ABAP system Source Client, else "   "
    CompTypes.ComponentTypes.TRACELIB,      // Corresponding Component Type (see ComponentTypes)
    Tools.Tools.createGUID(16),    // RootContextId
    Tools.Tools.createGUID(16),    // ConnectionId  
    1);                                     // ConnectionCounter

// Step 2
let strEpp = epp.getPassportAsString();     // get Header Value for SAP-PASSPORT header
console.info(strEpp);

// Step 1: Create a Copy of an existing Passport as Outbound Passport
let eppCopy = new libepp.DsrPassport();     // new DsrPassport Object
eppCopy.parsePassport(strEpp);              // parse header value strEpp into DsrPassport Object

// Step 2: Update relevant fields of the Outbound Passport
eppCopy.setConnectionId(Tools.Tools.createGUID(16));
eppCopy.setConnectionCount(1);
eppCopy.setPreviousComponent("DemoComponent_2");


let strHeader = "SAP-PASSPORT: " + eppCopy.getPassportAsString(); 
console.info(strHeader);

// Access a single SAP Passport field (e.g. TransactionId)

// Example for TransactionId
let transId = epp.getTransactionId();
console.info(transId);

// Example for ConnectionId
let connId = epp.getConnectionId()
console.info(connId);

// Example for ConnectionCounter
let connCt = epp.getConnectionCount()
console.info(connCt);

// Example for ComponentId (=== SystemId)
let compName = epp.getComponentId()
console.info(compName);

let version = epp.getVersion()
console.info(version);

let action = epp.getAction()
console.info(action)

console.info(epp.getPreviousComponentId())




gregorw
Active Contributor
0 Kudos

This is a public website. You're posing here NPM Libraries that are not public. Please reach out to your SAP internal colleagues to answer your questions.

former_member686997
Discoverer
0 Kudos

JavaScript node.js Examples

0. Preparation

use in node.js from nexus npm


add dependency to package.json: example below
{
  "name": "passport-js-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@sap/sapdsrpassport": "http://nexus3.wdf.sap.corp:8081/nexus/repository/deploy.releases.npm/@sap/sapdsrpassport/-/sapdsrpassport-1.0.2.tgz"
  }
}
npm install
gregorw
Active Contributor
0 Kudos

CAP should not care about the SAP Passport. The SAP Passport X.509 Client Certificate is used for authentication on the Identity Provider. This Identity provider is called from the Approuter. When successfully authenticated the approuter can get a JWT from the UAA Service. That is used for all service calls in CAP.