allanchiu.sh | 2023-07-24 08:57:27 UTC | #1
I just tried to connect GC via ClientCredential and copy the code from develop website.
const environment = platformClient.PureCloudRegionHosts[ORG_REGION]
const client = platformClient.ApiClient.instance
client.setEnvironment(environment)
client.loginClientCredentialsGrant(clientID,clientSecret)
.then(()=> {
// Do authenticated things
})
.catch((err) => {
// Handle failure response
console.log('Error')
console.log(err);
});
But got the error message say "Buffer is not defined" from apiClient.js. I don't know what is the problem as it is very basic function
allanchiu.sh | 2023-07-24 11:57:42 UTC | #2
I used js file and run by node it works but when i use vue it shows error message for Buffer is not defined
the only difference is how declare platformClient vue project - import platformClient from 'purecloud-platform-client-v2' js file: const platformClient = require('purecloud-platform-client-v2')
tim.smith | 2023-07-24 13:28:00 UTC | #3
allanchiu.sh, post:1, topic:21125
"Buffer is not defined"
allanchiu.sh, post:2, topic:21125
but when i use vue
This is an error with the packaging of your application. It works in a NodeJS because NodeJS natively provides the Buffer class. JavaScript in a browser does not provide this class so your packaging tool (webpack, rollup, etc) must provide the polyfill.
tim.smith | 2023-07-24 13:29:26 UTC | #4
Also, please note that client credentials are never acceptable to use via the browser. It also flat out won't work. You must use one of the other grants that are suitable for web apps. Assuming this is a client-side app, you should use the implicit grant. The SDK has a helper for this.
allanchiu.sh | 2023-07-26 12:34:42 UTC | #5
Thanks Tim, I got your point and used client.loginImplicitGrant(clientID, redirectUri, state), it works.
system | 2023-08-26 12:35:04 UTC | #6
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 21125