Integrating Brightspace with Zapier Private Apps Builder

LMS.S.479
LMS.S.479 Posts: 3 🔍
edited August 26 in Social Groups
Hi D2L Dev. I'm trying to build a private non listed app in Zapier using Brightspace public APIs but am struggling to pass the OAuth2 authentication step. It seems straight forward but something is not right.

Thanks in advance.

Error message received in the browser after authenticating thru the UI in Brightspace to collect the Access Token and Refresh Token the first time:

======

Zapier could not connect to your account.

The app returned "Unexpected Authorization scheme of "Bearer"". What happened (You are seeing this because you are an admin): Stack trace: ResponseError: {"status":400,"headers":{"content-type":"application/json","retry-after":null},"content":"{\"error\":\"unauthorized_client\",\"error_description\":\"Unexpected Authorization scheme of \\u0022Bearer\\u0022\",\"rfc6749_reference\":\"2.3.1, 4.1.2.1\"}","request":{"url":"https://auth.brightspace.com/core/connect/token"}} at _throwForStatus (/var/task/node_modules/zapier-platform-core/src/http-middlewares/after/prepare-response.js:13:11) at outResp.throwForStatus (/var/task/node_modules/zapier-platform-core/src/http-middlewares/after/prepare-response.js:70:5) at throwForStatusMiddleware (/var/task/node_modules/zapier-platform-core/src/http-middlewares/after/throw-for-status.js:5:14) at Object.<anonymous> (/var/task/node_modules/zapier-platform-core/src/middleware.js:80:37) From previous event: at /var/task/node_modules/zapier-platform-core/src/middleware.js:77:26 at Array.reduce (<anonymous>) at afterMiddleware (/var/task/node_modules/zapier-platform-core/src/middleware.js:76:21) at Object.<anonymous> (/var/task/node_modules/zapier-platform-core/src/middleware.js:94:18) From previous event: at Object.<anonymous> (/var/task/node_modules/zapier-platform-core/src/middleware.js:92:10) From previous event: at /var/task/node_modules/zapier-platform-core/src/middleware.js:89:45 at /var/task/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:266:18 at bound (node:domain:433:15) at runBound (node:domain:444:12) at process.processImmediate (node:internal/timers:476:21) at process.topLevelDomainCallback (node:domain:161:15) at process.callbackTrampoline (node:internal/async_hooks:126:24) From previous event: at Domain.<anonymous> (/var/task/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:250:10) at Domain.run (node:domain:389:15) at Runtime.handler (/var/task/node_modules/zapier-platform-core/src/tools/create-lambda-handler.js:246:19) at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)

=======

I wonder if anyone could point me the wrong piece in authentication after reading this source code that Zapier is generating:

{
"version": "1.0.0",
"platformVersion": "15.13.0",
"authentication": {
"type": "oauth2",
"test": {
"removeMissingValuesFrom": {
"body": false,
"params": false
},
"url": "https://xxx.brightspace.com/d2l/api/lp/1.35/users/whoami"
},
"oauth2Config": {
"authorizeUrl": {
"url": "https://auth.brightspace.com/oauth2/auth",
"params": {
"client_id": "{{process.env.CLIENT_ID}}",
"state": "{{bundle.inputData.state}}",
"redirect_uri": "{{bundle.inputData.redirect_uri}}",
"response_type": "code"
}
},
"getAccessToken": {
"body": {
"code": "{{bundle.inputData.code}}",
"client_id": "{{process.env.CLIENT_ID}}",
"client_secret": "{{process.env.CLIENT_SECRET}}",
"grant_type": "authorization_code",
"redirect_uri": "{{bundle.inputData.redirect_uri}}"
},
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json"
},
"method": "POST",
"removeMissingValuesFrom": {
"body": false,
"params": false
},
"url": "https://auth.brightspace.com/core/connect/token"
},
"refreshAccessToken": {
"body": {
"refresh_token": "{{bundle.authData.refresh_token}}",
"grant_type": "refresh_token"
},
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json"
},
"method": "POST",
"removeMissingValuesFrom": {
"body": false,
"params": false
},
"url": "https://auth.brightspace.com/core/connect/token"
},
"scope": "accommodations:*:* accountsettings:*:* alerts:*:* attributes:*:* awards:*:* calendar:*:* checklists:*:* content:*:* core:*:* datahub:*:* datasets:*:* discussions:*:* dropbox:*:* enrollment:*:* globalusermapping:*:* grades:*:* groups:*:* import:*:* ipsis:*:* languages:*:* localauthenticationsecurity:*:* lor:*:* lti:*:* ltiadvantage:*:* managefiles:*:* news:*:* organizations:*:* orgunits:*:* quizzing:*:* reporting:*:* role:*:* sections:*:* sessions:*:* surveys:*:* users:*:*",
"autoRefresh": false
},
"fields": []
},
"requestTemplate": {
"headers": {
"Authorization": "Bearer {{bundle.authData.access_token}}"
}
}
}

Comments

  • LMS.S.479
    LMS.S.479 Posts: 3 🔍

    Authentication step is working now!

    In Zapier authentication there are the steps to add the OAuth2 parameters that is straight forward (CliendID, ClientSecret, RedirectURL, Authorization Endpoint, Token Endpoint, Refresh Token Endpoint) and there is this "template" where some information that should be carried by every call would be added in it automatically.

    "requestTemplate": {"headers": {"Authorization": "Bearer {{bundle.authData.access_token}}"

    It was carrying this into the header in the very first call to request Access Token and it was causing problem. I removed it from template and explicit added it to the test call WhoAmI. It worked.

    "requestTemplate": {
    "headers": {
    "Authorization": "Bearer {{bundle.authData.access_token}}"