Where do I get the Workbench RESOURCE info in order to build a node.js ADD connection using ADAL?

Danilo Thome 1 Reputation point Microsoft Employee
2020-09-18T22:33:36.923+00:00

I'm using the following documentations as example:

https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/auth-samples/nodejs

const AUTHORITY = 'https://login.microsoftonline.com/goncalves.us';
const WORKBENCH_API_URL = 'https://workbench-6fwqfk-api.azurewebsites.net';
const RESOURCE = 'https://goncalves.us/69f59863-8c80-4b13-9acf-5ebcf3e34e32';
const CLIENT_APP_Id = 'b38d0a3f-832a-4b4f-b24a-ff4c17bb4139';
const CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXX';

PS S:\Project\RewardsChain\Web\src\js> node .\aad.js Error: Request failed with status code 401
at createError (S:\Project\RewardsChain\Web\node_modules\axios\lib\core\createError.js:16:15)
at settle (S:\Project\RewardsChain\Web\node_modules\axios\lib\core\settle.js:18:12)
at IncomingMessage.handleStreamEnd (S:\Project\RewardsChain\Web\node_modules\axios\lib\adapters\http.js:192:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
config: {
adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, /',
Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyIsImtpZCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyJ9.eyJhdWQiOiJodHRwczovL2dvbmNhbHZlcy51cy82OWY1OTg2My04YzgwLTRiMTMtOWFjZi01ZWJjZjNlMzRlMzIiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb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 'get',
url: 'https://workbench-6fwqfk-api.azurewebsites.net/api/v1/users',
data: undefined
},
request: ClientRequest {
_events: [Object: null prototype] {
socket: [Function],
abort: [Function],
aborted: [Function],
error: [Function],
timeout: [Function],
prefinish: [Function: requestOnPrefinish]
},
_eventsCount: 6,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: true,
_SNICallback: null,
servername: 'workbench-6fwqfk-api.azurewebsites.net',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 10,
connecting: false,
_hadError: false,
_parent: null,
_host: 'workbench-6fwqfk-api.azurewebsites.net',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(asyncId)]: 26,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
connection: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: true,
_SNICallback: null,
servername: 'workbench-6fwqfk-api.azurewebsites.net',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 10,
connecting: false,
_hadError: false,
_parent: null,
_host: 'workbench-6fwqfk-api.azurewebsites.net',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(asyncId)]: 26,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
_header: 'GET /api/v1/users HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyIsImtpZCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyJ9.eyJhdWQiOiJodHRwczovL2dvbmNhbHZlcy51cy82OWY1OTg2My04YzgwLTRiMTMtOWFjZi01ZWJjZjNlMzRlMzIiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC84MjYwOGM1OS1jZDkzLTQ2ZWItODkxMS1iZjM2ZTFiYWFjOTgvIiwiaWF0IjoxNjAwNDY3OTk4LCJuYmYiOjE2MDA0Njc5OTgsImV4cCI6MTYwMDQ3MTg5OCwiYWlvIjoiRTJCZ1lLZ3NaRkIwc3ZNNlY5TzROVEhsL2ZjTkFBPT0iLCJhcHBpZCI6ImIzOGQwYTNmLTgzMmEtNGI0Zi1iMjRhLWZmNGMxN2JiNDEzOSIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzgyNjA4YzU5LWNkOTMtNDZlYi04OTExLWJmMzZlMWJhYWM5OC8iLCJvaWQiOiJhNDVlNmMxYy0xMTBlLTQzYTgtOTIwOC1lNDc3Y2NhNGQyNjQiLCJyaCI6IjAuQUFBQVdZeGdncFBONjBhSkViODI0YnFzbUQ4S2piTXFnMDlMc2tyX1RCZTdRVGswQUFBLiIsInN1YiI6ImE0NWU2YzFjLTExMGUtNDNhOC05MjA4LWU0NzdjY2E0ZDI2NCIsInRpZCI6IjgyNjA4YzU5LWNkOTMtNDZlYi04OTExLWJmMzZlMWJhYWM5OCIsInV0aSI6IjZjXzlvN0l5SGt1Z1JXUWZ5LTAzQUEiLCJ2ZXIiOiIxLjAifQ.o8I3kQZS_kjleSvTxGZgxELk6QgF8cYQQeYJVEiIfXCT6zNn2z8rH5wjLBL35VsBTtwx-f14fias5Ktm-ksLSl9ZW2MIJGlVAqLNUpV36s4TebmAA08tJChgBB-sDn0zX4Jzdf2dgY2oB_p49PT_wwgKenRFHlc_F7GZ7S9SNfp-7vBPVDd7jEppwJMLFwIMeEIbFGZ-dg1V9zL2ygWsiF61_sn3cUE_ETob3BBbgexVZ8tPJqfHWCRmk7w2nNAKveE4QZnonagatPnHCoe_XZUvSyU2mM5AbDD2hy_dr73EFBOvoO3ccYuHF6kWaFxOgORFQFspKBdOp9oO3xEO5w\r\n' +
'User-Agent: axios/0.17.1\r\n' +
'Host: workbench-6fwqfk-api.azurewebsites.net\r\n' +
'Connection: close\r\n' +
'\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
insecureHTTPParser: undefined,
path: '/api/v1/users',
_ended: true,
res: IncomingMessage {
_readableState: [ReadableState],
readable: false,
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
socket: [TLSSocket],
connection: [TLSSocket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 401,
statusMessage: 'Unauthorized',
client: [TLSSocket],
_consuming: false,
_dumped: false,
req: [Circular],
responseUrl: 'https://workbench-6fwqfk-api.azurewebsites.net/api/v1/users',
redirects: [],
[Symbol(kCapture)]: false
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
_redirectable: Writable {
_writableState: [WritableState],
writable: true,
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_options: [Object],
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function],
_currentRequest: [Circular],
_currentUrl: 'https://workbench-6fwqfk-api.azurewebsites.net/api/v1/users',
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
authorization: [Array],
'user-agent': [Array],
host: [Array]
}
},
response: {
status: 401,
statusText: 'Unauthorized',
headers: {
server: 'Kestrel',
'www-authenticate': 'Bearer error="invalid_token", error_description="The audience is invalid"',
'request-context': 'appId=cid-v1:2e66350f-e735-4914-9bc7-6808747666b2',
'x-correlation-id': 'd25a45b0-9c99-43ab-bf49-abb7f3583e84',
'set-cookie': [Array],
date: 'Fri, 18 Sep 2020 22:31:37 GMT',
connection: 'close',
'content-length': '0'
},
config: {
adapter: [Function: httpAdapter],
transformRequest: [Object],
transformResponse: [Object],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'get',
url: 'https://workbench-6fwqfk-api.azurewebsites.net/api/v1/users',
data: undefined
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 6,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header: 'GET /api/v1/users HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyIsImtpZCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyJ9.eyJhdWQiOiJodHRwczovL2dvbmNhbHZlcy51cy82OWY1OTg2My04YzgwLTRiMTMtOWFjZi01ZWJjZjNlMzRlMzIiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC84MjYwOGM1OS1jZDkzLTQ2ZWItODkxMS1iZjM2ZTFiYWFjOTgvIiwiaWF0IjoxNjAwNDY3OTk4LCJuYmYiOjE2MDA0Njc5OTgsImV4cCI6MTYwMDQ3MTg5OCwiYWlvIjoiRTJCZ1lLZ3NaRkIwc3ZNNlY5TzROVEhsL2ZjTkFBPT0iLCJhcHBpZCI6ImIzOGQwYTNmLTgzMmEtNGI0Zi1iMjRhLWZmNGMxN2JiNDEzOSIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzgyNjA4YzU5LWNkOTMtNDZlYi04OTExLWJmMzZlMWJhYWM5OC8iLCJvaWQiOiJhNDVlNmMxYy0xMTBlLTQzYTgtOTIwOC1lNDc3Y2NhNGQyNjQiLCJyaCI6IjAuQUFBQVdZeGdncFBONjBhSkViODI0YnFzbUQ4S2piTXFnMDlMc2tyX1RCZTdRVGswQUFBLiIsInN1YiI6ImE0NWU2YzFjLTExMGUtNDNhOC05MjA4LWU0NzdjY2E0ZDI2NCIsInRpZCI6IjgyNjA4YzU5LWNkOTMtNDZlYi04OTExLWJmMzZlMWJhYWM5OCIsInV0aSI6IjZjXzlvN0l5SGt1Z1JXUWZ5LTAzQUEiLCJ2ZXIiOiIxLjAifQ.o8I3kQZS_kjleSvTxGZgxELk6QgF8cYQQeYJVEiIfXCT6zNn2z8rH5wjLBL35VsBTtwx-f14fias5Ktm-ksLSl9ZW2MIJGlVAqLNUpV36s4TebmAA08tJChgBB-sDn0zX4Jzdf2dgY2oB_p49PT_wwgKenRFHlc_F7GZ7S9SNfp-7vBPVDd7jEppwJMLFwIMeEIbFGZ-dg1V9zL2ygWsiF61_sn3cUE_ETob3BBbgexVZ8tPJqfHWCRmk7w2nNAKveE4QZnonagatPnHCoe_XZUvSyU2mM5AbDD2hy_dr73EFBOvoO3ccYuHF6kWaFxOgORFQFspKBdOp9oO3xEO5w\r\n' +
'User-Agent: axios/0.17.1\r\n' +
'Host: workbench-6fwqfk-api.azurewebsites.net\r\n' +
'Connection: close\r\n' +
'\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'GET',
insecureHTTPParser: undefined,
path: '/api/v1/users',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: ''
}
}

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
38,722 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SanaCMSFT-8922 301 Reputation points
    2020-10-08T09:18:55.907+00:00

    Hi @Danilo Thome ,

    From your error message, I see that you are getting "The audience is invalid" error. Invalid audience usually means that the token was not requested for the right authority. You would have to provide the correct App Id of your workbench API which is what you have to provide for RESOURCE. You can check your app Id through the portal, if you click on the API app service.

    30907-tempsnipqa.png

    Let us know if this solves your issue.

    Thanks,
    Sana

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.