ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

External authentication #281

Closed fspugna closed 2 years ago

fspugna commented 2 years ago

Hi, I want to add a chat in my React Native app but I have not clear how to implement the External Authentication.

What I understood is this:

  1. User connect to my backend and get a token
  2. then I should call https://api.connectycube.com/login in POST with this params:
    • login = token received from my backend
    • password = random value for validation
  3. login should return a connecty cube token that I can finally use for initialize ( init method that accept app_id and this token I received from login api)

I am stuck at step 2. I get an error 403. If I test with Postman I get "errors": [ "Token is required" ]

What token is required?

Thanks in advance for your help!

natalialuzuriaga commented 2 years ago

Hi there,

I am getting the same error as well. Any guidance would be much appreciated!

DaveLomber commented 2 years ago

Basically the solution is pretty simple

In order to call any ConnectyCube API (except 'createSession') - you need a ConnectyCube Session token which can be created using https://api.connectycube.com/session in POST

So the flow should be like this:

  1. User connect to external backend and get a token
  2. Then call https://api.connectycube.com/session in POST and create an anonymous session
  3. Then - call https://api.connectycube.com/login in POST with this params: login = token received from backend password = random value for validation

So the logs request will upgrade the ConnectyCube Session token from step2 and make it user-aware.

Then all the further calls to AOI should just work