I have a implicit grant app tested using stand along web server and also as an app in cloud itself.
All the APIs function correctly except opening the WebSocket for notifications. This always produces CORS errors
...subscription from origin .... has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
The origin is one of the callback URLs in the OAuth
I found the video on youtube for DevCast Tutorial #3 | How to Create PureCloud Custom Client Apps and Utilize the Client App SDK
Is the source code for the GC parts available?
How is he not getting a CORS error?
Can you provide details? What API resource are you referring to specifically? CORS errors like this are usually caused by your request being malformed in some way making the API server unable to process it as expected and therefore unable to return a successful response to the CORS check.
In your browser's dev tools, on the network tab, right click on the failed request and select Copy as cURL . Paste this into a text editor and you should see it start with something like curl 'https://api.mypurecloud.com/api....
. Add a -v
after curl
so you get curl -v 'https://api....
and run that in a shell on your computer. That will show you all the headers being sent and will verbosely display the response. If you're not sure why your request is failing after seeing that, please post the FULL output of the command here, being sure to redact your access token and any PII that may be present in the request (please leave the correlation ID in tact).
We do have a lot of open source projects here: https://github.com/MyPureCloud
The requests are being made correctly to pass CORS checks.
Hi Tim.
I am sucessfully calling notificationsApi.postNotificationsChannels()
channel: {status: 200, statusText: 'OK', headers: {…}, body: {…}, text: '{"connectUri":"wss://streaming.mypurecloud.com.au/…k3du83f67i","expires":"2022-01-07T00:14:28.941Z"}', …}
I use io-socket.client( channel.body.connectUri ) and get a success
Socket {io: Manager, nsp: '/channels/streaming-2-4o0qk00ff8j8obeak3du83f67i', json: Socket, ids: 0, acks: {…}, …}
At this point the web socket software kicks off but I get
localhost/:1 Access to XMLHttpRequest at 'https://streaming.mypurecloud.com.au/socket.io/?EIO=3&transport=polling&t=NuilAeh ' from origin 'http://localhost:3000 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Following your advice (thank you) I run the URl trough curl -v but end up with a 404 (explaining the CORS)
curl -v 'https://streaming.mypurecloud.com.au/socket.io/?EIO=3&transport=polling&t=NuilAeh '
Trying 52.64.226.45:443...
Connected to streaming.mypurecloud.com.au (52.64.226.45) port 443 (#0 )
ALPN, offering h2
ALPN, offering http/1.1
successfully set certificate verify locations:
CAfile: /etc/ssl/cert.pem
CApath: none
TLSv1.2 (OUT), TLS handshake, Client hello (1):
TLSv1.2 (IN), TLS handshake, Server hello (2):
TLSv1.2 (IN), TLS handshake, Certificate (11):
TLSv1.2 (IN), TLS handshake, Server key exchange (12):
TLSv1.2 (IN), TLS handshake, Server finished (14):
TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
TLSv1.2 (OUT), TLS handshake, Finished (20):
TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
TLSv1.2 (IN), TLS handshake, Finished (20):
SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
ALPN, server accepted to use h2
Server certificate:
subject: CN=mypurecloud.com.au
start date: Oct 21 00:00:00 2021 GMT
expire date: Nov 19 23:59:59 2022 GMT
subjectAltName: host "streaming.mypurecloud.com.au " matched cert's "*.mypurecloud.com.au"
issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
SSL certificate verify ok.
Using HTTP2, server supports multi-use
Connection state changed (HTTP/2 confirmed)
Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
Using Stream ID: 1 (easy handle 0x12580ec00)
GET /socket.io/?EIO=3&transport=polling&t=NuilAeh HTTP/2
Host: streaming.mypurecloud.com.au
user-agent: curl/7.77.0
accept: /
Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 404
< date: Thu, 06 Jan 2022 00:15:41 GMT
< content-type: text/html;charset=iso-8859-1
< content-length: 378
< cache-control: must-revalidate,no-cache,no-store
<
Error 404 Not Found
HTTP ERROR 404 Not Found
URI:
/socket.io/
STATUS:
404
MESSAGE:
Not Found
SERVLET:
dispatcherServlet
* Connection #0 to host streaming.mypurecloud.com.au left intact
Are you able to make sense of this?
I have redone the test using the WebSocket APi instead of web-socket.client() - ie.e doing it correctly
I get my channel
{status: 200, statusText: 'OK', headers: {…}, body: {…}, text: '{"connectUri":"wss://streaming.mypurecloud.com.au/…seb19kv71r","expires":"2022-01-07T00:42:00.846Z"}', …}
body: {connectUri: 'wss://streaming.mypurecloud.com.au/channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r', id: 'streaming-2-mokn9ldj0d2fu4u9seb19kv71r', expires: '2022-01-07T00:42:00.846Z'}
error: null
headers: {cache-control: 'no-cache, no-store, must-revalidate', content-length: '182', content-type: 'application/json', inin-correlation-id: '4ef961b8-8419-4685-b40a-4c7687d863cb'}
status: 200
statusText: "OK"
text: "{"connectUri":"wss://streaming.mypurecloud.com.au/channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r","id":"streaming-2-mokn9ldj0d2fu4u9seb19kv71r","expires":"2022-01-07T00:42:00.846Z"}"
[[Prototype]]: Object
I call webSocket = new WebSocket( channel.body.connectUri )
I get the webSocket
WebSocket {_events: {…}, _eventsCount: 0, _maxListeners: undefined, readyState: 0, protocol: '', …}
protocol: ""
readyState: 2
url: "wss://streaming.mypurecloud.com.au/channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r"
_binaryType: "nodebuffer"
_closeCode: 1006
_closeFrameReceived: false
Then the socket s/w take over and I get
Access to fetch at 'https://streaming.mypurecloud.com.au/channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r ' from origin 'http://localhost:3000 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Running curl seems to work but I get the CORS error. http://localhost:3000 is in the implict frant redirect URL.
mikehardie@Mikes-Mac-mini emailpicker % curl -v 'https://streaming.mypurecloud.com.au/channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r '
Trying 52.64.226.45:443...
Connected to streaming.mypurecloud.com.au (52.64.226.45) port 443 (#0 )
ALPN, offering h2
ALPN, offering http/1.1
successfully set certificate verify locations:
CAfile: /etc/ssl/cert.pem
CApath: none
TLSv1.2 (OUT), TLS handshake, Client hello (1):
TLSv1.2 (IN), TLS handshake, Server hello (2):
TLSv1.2 (IN), TLS handshake, Certificate (11):
TLSv1.2 (IN), TLS handshake, Server key exchange (12):
TLSv1.2 (IN), TLS handshake, Server finished (14):
TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
TLSv1.2 (OUT), TLS handshake, Finished (20):
TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
TLSv1.2 (IN), TLS handshake, Finished (20):
SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
ALPN, server accepted to use h2
Server certificate:
subject: CN=mypurecloud.com.au
start date: Oct 21 00:00:00 2021 GMT
expire date: Nov 19 23:59:59 2022 GMT
subjectAltName: host "streaming.mypurecloud.com.au " matched cert's "*.mypurecloud.com.au"
issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
SSL certificate verify ok.
Using HTTP2, server supports multi-use
Connection state changed (HTTP/2 confirmed)
Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
Using Stream ID: 1 (easy handle 0x13a80ce00)
GET /channels/streaming-2-mokn9ldj0d2fu4u9seb19kv71r HTTP/2
Host: streaming.mypurecloud.com.au
user-agent: curl/7.77.0
accept: /
Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 400
< date: Thu, 06 Jan 2022 00:43:40 GMT
< content-length: 34
<
Connection #0 to host streaming.mypurecloud.com.au left intact
Hi Tim, what I did not mention is that I was doing this in a Reaxct app - so if some one has some example code of doing notifications in react then that would be most appreciated.
I have it working using JS embedded in HTML and it works as expected.
Thanks for your help
Mike
You can't use socket.io. That's a communication framework built on top of WebSockets; it cannot be used as a generic WebSocket client. Introduction | Socket.IO
You should be using the JavaScript's native WebSocket implementation.
system
Closed
February 11, 2022, 1:14pm
8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.