Failed to get access token: no valid JWT bearer found while accessing S4HANA via OAuth2Bearer - sap

I've generated project via:
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.s4hana.archetypes -DarchetypeArtifactId=scp-cf-spring -DarchetypeVersion=LATEST
I included S4Sdk jars and accessing S4Hana V2 API. The code works fine with Basic authentication but when I configure destination type as "OAuth2SAMLBEARER ASSERTION" I get the following error in CF logs when accessing S4Hana API's via .execute calls. :
2018-09-07T06:37:22.728+0000 [APP/PROC/WEB/0] ERR ... 1 more
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get access token for destination service.
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.getAccessToken(DestinationServiceCommand.java:107)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.run(DestinationServiceCommand.java:117)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.run(DestinationServiceCommand.java:26)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR ... 26 more
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequestFailedException: Failed to get access token: no valid JWT bearer found in "Authorization" header of request.
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.getCurrentJwt(TokenRequest.java:307)
2018-09-07T06:37:22.729+0000 [APP/PROC/WEB/0] ERR at com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.requestTokenWithUserTokenGrant(TokenRequest.java:348)
Note I've established trust between S4Hana system and subaccount, communication and business users are configured, principal propagation steps as specified in: https://blogs.sap.com/2018/02/05/deep-dive-8-with-sap-s4hana-cloud-sdk-leverage-principal-propagation-via-oauth-2-when-consuming-a-business-api-from-s4hana-cloud/ ,
Please check and let me know if something else needs to be configured for this.
I tried creating approuter via blog suggested in comments but i'm getting error in deploying approuter in cf:
2018-09-07T20:01:21.20+0530 [APP/PROC/WEB/0] OUT > #sap/approuter#2.10.0 start /home/vcap/app
2018-09-07T20:01:21.20+0530 [APP/PROC/WEB/0] OUT > node approuter.js
2018-09-07T20:01:25.50+0530 [APP/PROC/WEB/0] OUT #2.0#2018 09 07 14:31:25:497#+00:00#WARNING#/LoggingLibrary################PLAIN##Dynamic log level switching not available#
2018-09-07T20:01:28.89+0530 [APP/PROC/WEB/0] OUT #2.0#2018 09 07 14:31:28:897#+00:00#INFO#/approuter################PLAIN##Application router version 2.10.0#
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR /home/vcap/app/lib/utils/JsonValidator.js:30
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR throw new VError('%s%s: %s',
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR ^
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR VError: environment-destinations/0/url: Format validation failed (URI must be absolute)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at JsonValidator.validate (/home/vcap/app/lib/utils/JsonValidator.js:30:11)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Object.validateEnvDestinations (/home/vcap/app/lib/configuration/validators.js:100:15)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at loadDestinations (/home/vcap/app/lib/configuration/env-config.js:55:14)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Object.load (/home/vcap/app/lib/configuration/env-config.js:20:28)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Object.module.exports.load (/home/vcap/app/lib/configuration.js:15:37)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at bootstrap (/home/vcap/app/lib/bootstrap.js:47:36)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Approuter.start (/home/vcap/app/approuter.js:58:13)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Object.<anonymous> (/home/vcap/app/approuter.js:115:6)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Module._compile (module.js:577:32)
2018-09-07T20:01:29.00+0530 [APP/PROC/WEB/0] ERR at Object.Module._extensions..js (module.js:586:10)
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! Linux 4.4.0-133-generic
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! argv "/home/vcap/deps/0/node/bin/node" "/home/vcap/deps/0/bin/npm" "start"
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! node v6.14.3
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! npm v3.10.10
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! #sap/approuter#2.10.0 start: `node approuter.js`
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR!
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! Failed at the #sap/approuter#2.10.0 start script 'node approuter.js'.
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! Make sure you have the latest version of node.js and npm installed.
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! If you do, this is most likely a problem with the #sap/approuter package,
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! not with npm itself.
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! Tell the author that this fails on your system:
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! node approuter.js
2018-09-07T20:01:29.19+0530 [APP/PROC/WEB/0] ERR npm ERR! You can get information on how to open an issue for this project with:
2018-09-07T20:01:29.20+0530 [APP/PROC/WEB/0] ERR npm ERR! npm bugs #sap/approuter
2018-09-07T20:01:29.20+0530 [APP/PROC/WEB/0] ERR npm ERR! Or if that isn't available, you can get their info via:
2018-09-07T20:01:29.20+0530 [APP/PROC/WEB/0] ERR npm ERR! npm owner ls #sap/approuter
2018-09-07T20:01:29.20+0530 [APP/PROC/WEB/0] ERR npm ERR! There is likely additional logging output above.
2018-09-07T20:01:29.29+0530 [APP/PROC/WEB/0] ERR npm ERR! Please include the following file with any support request:
2018-09-07T20:01:29.29+0530 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/npm-debug.log
Can you please help me here. I downloaded approuter from the link suggested in blog.

The issue was solved by having app router send the JWT token to Java application. There are set of files like xs-app.json that needs to be configured with the correct regular expression for the map to destinations created in manisfest.yml of your app router. The specific destination created in the manifest should point to your java service with "forward-token: true".
Apart from this, your XSUAA service instance created should have proper auth scopes defined in xs-secuity.json as required by your application.
For above error, if we call the java service with bearer token as received from app router it works fine. You can also access the app directly from app router by configuring proper regex in xs-app.json.

I guess authentication is not configured yet as explained here: https://blogs.sap.com/2017/07/18/step-7-with-sap-s4hana-cloud-sdk-secure-your-application-on-sap-cloud-platform-cloudfoundry/
Have you secured your app so that the user has to log in first?
In contrast to Basic Authentication, for OAuth2SAMLBEARER or any other propagation of the user principle, the user has to be logged in into the application beforehand. Only then, the user can be propagated.
You logs indicate that the application fails to extract the JWT token from the request, which should be passed from the approuter.

Related

npm v8.5.0 fails with sslv3 alert handshake failure

We have an Organization base Artifactory setup which has a Client-certificate based authentication and the then user level authentication enabled.
Recently after the update of npm to v8.5.0, the npm starting failing while connecting to the the artifactory repository.
Following error message is displayed:
npm ERR! code EPROTO
npm ERR! syscall write
npm ERR! errno EPROTO
npm ERR! request to https://mycompany.com/artifactory/api/npm/pvh-platform-npm/npm failed, reason: write EPROTO 3848:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:c:\ws\deps\openssl\openssl\ssl\record\rec_layer_s3.c:1546:SSL alert number 40
npm ERR!
Note: The artifactory url is accessible from the system via any browser.
And the client-certificate is configured in the Windows Credentials Manager.

How to solve error “SyntaxError: Unexpected token” and “npm ERR! code ELIFECYCLE”

I receive the following error when I run npm start. Could anyone please help me with this issue. I encounter it only on Windows 10; everything works fine on macOS.
Here is the traceback:
$ npm start
> webpack-boilerplate#1.0.0 start E:\Projects\Upwork_Projects\wellness-osteo\markup
> webpack-dev-server --open --config webpack.dev.js
E:\Projects\Upwork_Projects\wellness-osteo\markup\node_modules\copy-webpack-plugin\node_modules\p-limit\index.js:30
} catch {}
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\Projects\Upwork_Projects\wellness-osteo\markup\node_modules\copy-webpack-plugin\dist\index.js:12:38)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpack-boilerplate#1.0.0 start: `webpack-dev-server --open --config webpack.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpack-boilerplate#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\krish\AppData\Roaming\npm-cache\_logs\2020-09-08T17_46_12_163Z-debug.log
This is because the catch statement is missing an exception variable
it should have been written as
} catch (e) { }
This has been resolved as of copy-webpack-plugin^#6.3.0
Try upgrading / downgrading to an earlier version to resolve this.
c.f try/catch block in the Javascript MDN documentation

npm ERR! request to https://registry.npmjs.org/ngx-pagination failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443

While installing any npm package, I am getting the same error every time.
Tried to remove and set proxy but it didn't work.
tabish#appventurez:~/Documents/projects/InstaCEI/InstaCEI_Website$ sudo npm i ngx-pagination --save
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/ngx-pagination failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443
npm ERR! A complete log of this run can be found in:
npm ERR! /home/tabish/.npm/_logs/2019-06-19T11_27_35_023Z-debug.log
tabish#appventurez:~/Documents/projects/InstaCEI/InstaCEI_Website$ sudo npm i ngx-pagination --save
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/ngx-pagination failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443
npm ERR! A complete log of this run can be found in:
npm ERR! /home/tabish/.npm/_logs/2019-06-19T11_27_35_023Z-debug.log
One reason is about your IP address setup.
Check ip addr, ping, and netplan if ubuntu.
In my example, I setup a static IP of an ubuntu (18.04) VM, but I forgot the DNS.
Then I got the exactly same error as you.
I fix this problem by changing the file /etc/netplan/50-cloud-init.yaml as below:
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens33:
addresses: [192.168.233.132/24]
dhcp4: no
gateway4: 192.168.233.2
optional: true
nameservers:
addresses: [223.5.5.5, 8.8.8.8]
version: 2

npm cannot install packages, access denied to .npm cache folder

When running npm install on a local project, I get this error:
npm ERR! Error: EACCES: permission denied. The operation was rejected by your operating system. It is likely you do not have the permissions to access this file as the current user
For unclear reasons, it seems that a global .npm folder is causing the troubles.
path /Users/erik/.npm/_cacache/index-v5/ab/a6/079836a3c186b5fd2d717a4
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied
I tried forcing the install with sudo npm install but then I get these errors:
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
Worst of all, it seems that npm is no longer working now, when executing any npm command I get this very weird error
npm -v
const path = i >= 0 ? args[i] : process.cwd(); Error: ENOENT: no such file or directory, uv_cwd
How can I fix these permission issues? Even locally I am not allowed to use npm install.

Unable to install web3 js for windows10

The problem is to unable to install web3 js for windows10. I tried to install the latest version of Web3 js using the command:
npm install --save web3#1.0.0-beta.46
The error in terminal:
PS C:\Users\RSky> npm install --save web3#1.0.0-beta.46
> scrypt#6.0.3 preinstall C:\Users\RSky\node_modules\scrypt
> node node-scrypt-preinstall.js
> scrypt#6.0.3 install C:\Users\RSky\node_modules\scrypt
> node-gyp rebuild
C:\Users\RSky\node_modules\scrypt>if not defined npm_config_node_gyp (node "C:\Users\RSky\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\RSky\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'nan'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at [eval]:1:1
at Script.runInThisContext (vm.js:119:20)
at Object.runInThisContext (vm.js:326:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at evalScript (internal/bootstrap/node.js:589:27)
gyp: Call to 'node -e "require('nan')"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\RSky\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\RSky\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\RSky\node_modules\scrypt
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\RSky\package.json'
npm WARN RSky No description
npm WARN RSky No repository field.
npm WARN RSky No README data
npm WARN RSky No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt#6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt#6.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\RSky\AppData\Roaming\npm-cache\_logs\2019-03-05T18_04_48_554Z-debug.log
What the cause of that error?
Replace
window.contractInstance = new web3.eth.contract(abi, myContractAddress)
With
window.contractInstance = new window.web3.eth.contract(abi, myContractAddress)
in contract you have
constructor() public {
owner == msg.sender;
}
is it correct?
shouldn't it be
constructor() public {
owner = msg.sender;
}
UPDATE 1:
// Web3.js instance
window.web3 = new Web3(web3.currentProvider);
you are writing web3.currentProvider. But in your code web3 is not declared anywhere. Is it declared in head?
From your code I understand that you are not using metamask. If we use metamask it injects a version of web3 library into a page. We can use it to get a web3 instance like
var web3 = new Web3(window.web3.currentProvider);
But if we are not using metamask we need to use a 3rd party provider to get the web3 instance like infura and the above line of code will change to
var web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/<<your infura token>>"));
UPDATE 2:
change
// Contract instance
window.contractInstance = new window.web3.eth.contract(abi,myContractAddress)
contractInstance.owner((err, ownerValue) => {
document.querySelector('#owner-address').innerHTML(ownerValue)
})
to
// Contract instance
window.contractInstance = window.web3.eth.contract(abi).at(myContractAddress)
contractInstance.owner((err, ownerValue) => {
document.querySelector('#owner-address').innerHTML = ownerValue;
})
I deployed same contract on Rinkeby test net and its working. Contract address 0x104ec30CD6FDC5889eDff672b7ac8a2a42232F64
UPDATE 3:
Question was edited and now this answer doesn't go with the question.