ConnectyCube / connectycube-reactnative-samples

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

External authentication via Custom Identity Provider problem #91

Closed Jempan closed 3 years ago

Jempan commented 4 years ago

Hi! Following the instructions for external authentication via Custom Identity Provider at https://developers.connectycube.com/guides/custom-identity-provider but feel that some information is missing. The call to https://api.connectycube.com/login obviously requires a "token". Is it an application session token and if so how can I retrieve it? Trying to run:

ConnectyCube.init(config) ConnectyCube.createSession() .then((session) => {}) .catch((error) => {});

But I don't get any session information back. Guess I misunderstood something?

DaveLomber commented 4 years ago

Please try something like this:

ConnectyCube.init(config)

ConnectyCube.createSession().then(session => {

   ConnectyCube.login(userCredentials)
       .then((user) => {})
     .catch((error) => {});

}) .catch(error => {

});
Jempan commented 4 years ago

Thanks for your answer! Tried your suggested way of creating a session but the answer from your server is catched as an error even though the status code is 201 (created). So the ConnectyCube.login line never happens. Anyway I want to use our own user database and authentication system and then I can't log users in that way can I?

When I follow the instructions on https://developers.connectycube.com/guides/custom-identity-provider I get "token is required" on the login post request which makes sense since your server could not know who I am. Is that response not referring to a session token?

DaveLomber commented 4 years ago

Please try the following:

ConnectyCube.init(config)

ConnectyCube.createSession(userCredentials).then(session => {

}) .catch(error => {

});
Jempan commented 4 years ago

Now I get a 401-error back without any more info. Which userCredentials do you want me to try here?

DaveLomber commented 4 years ago

The same what you pass into login request

Please provide the following: 1) what params you pass in userCredentials 2) What exact error you receive? 3) what you defined as Custom Identity Provider settings in admin panel

Jempan commented 4 years ago

It's working now. I can see in our log that the verification call from ConnectyCube reaches the right endpoint on our server and the custom user is also added to the user list in your admin panel. Does this mean that i don't have to do the login post call described in https://developers.connectycube.com/guides/custom-identity-provider?

ConnectyCube.createSession(userCredentials).then(session => {
      console.log("VideoService initialized and session created "+JSON.stringify(session)) 
    }).catch(error => {
      console.log("VideoService initialized error "+JSON.stringify(error)) 
    });

Above call gives me VideoService initialized error {"code":201,"info":" "} but if I don't need any information from the session object I guess it doesn't matter :)

DaveLomber commented 4 years ago

It's totally fine to use single ConnectyCube.createSession(userCredentials) instead of creating an empty session and then user login, so this should be fine 👍

Jempan commented 4 years ago

Trying to start a video conference and updated above code to:

ConnectyCube.createSession(userCredentials).then(session => {
      console.log("VideoService initialized and session created "+JSON.stringify(session)); 
    }).catch(error => {
      console.log("VideoService initialized error "+JSON.stringify(error)); 
      this.videoConference = ConnectyCube.videochatconference.createNewSession();
    });

but I get an error "Error: Session does not exist at ConferenceClient.getCurrentSessionToken". Is the session I started not good for video conferences?

DaveLomber commented 4 years ago

Could you please try the following:

    ConnectyCube.createSession(userCredentials).then(session => {
      console.log("session resp", session); 
      console.log("session", ConnectyCube.sdkInstance.session); 
      this.videoConference = ConnectyCube.videochatconference.createNewSession();
    }).catch(error => {
      console.log("session error", error); 
    });

you should create a conf session once you got a success session, not inside catch error callback

Jempan commented 4 years ago

Hi again and thanks for your reply! If you look at my comment 21 hours ago you can see that when I use your library ConnectyCube.createSession(userCredentials) it returns in the catch error clause and logs error {"code":201,"info":" "} and I don't get a session object back. Has no one else experienced that before, could it be because I use the custom identity provider option?

DaveLomber commented 4 years ago

@Jempan I'm not sure I can understand what's wrong

Can you do one thing - open browser's console, network tab Then copy past a screenshot of the response obtained for the session creation request - both body and headers

It will help to understand what's going on

Jempan commented 4 years ago

Skärmavbild 2020-07-01 kl  21 36 52

Jempan commented 4 years ago

Skärmavbild 2020-07-01 kl  21 37 21

DaveLomber commented 4 years ago

Total mystery.. Status code is 201 but no body

One thing to try - could you please try to use Chrome browser standard debugger, not a React Native debugger and let us know how it works.

Jempan commented 4 years ago

Here is the full response header also. Skärmavbild 2020-07-01 kl  21 50 10

DaveLomber commented 4 years ago

Yes headers are fine, status code is good as well (201) And there should be a response body for sure

DaveLomber commented 4 years ago

Also please provide your app id we will check against backend logs what can be an issue

Jempan commented 4 years ago

Yes it's very strange. Unfortunately I have never been able to debug this app using chrome browser standard debugger, network calls doesn't work without react native debugger :( Where can I give you my app id without posting it in the open here? Maybe you can identify me in the logs now that you have the exact time of the call?

DaveLomber commented 4 years ago

Ok we identified it

we see your backend responses with '415 Unsupported Media Type' error when we do a request to it to verify the data

Could you please double check this part and adjust custom idp settings in admin panel

maybe it's required to add some request headers there e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415

Jempan commented 4 years ago

That's even stranger, my server log shows the request from you guys without any errors and response code 200 🤔 And the custom user was also created in the admin user list which I guess shouldn't happen if you didn't get a 200 response?

Jempan commented 4 years ago

Skärmavbild 2020-07-01 kl  22 24 24

Do you have anymore information about the request from your side. This is what I can se in my logs and it looks correct 🤔

Jempan commented 4 years ago

Tried to add many different combinations of headers without any luck. Still can't see any info about 415-errors in my server log, only 200 responses. One question, when I change the settings (for example header) in your admin can I test it directly or does the changes takes time to go through?

Tested that I get a 200 response with a uid in the response when I call my endpoint from postman and copied the same headers to your admin but it still not work. Don't know what else to test without more info from you.

DaveLomber commented 4 years ago

@Jempan please let us know what's your app id

Jempan commented 4 years ago

@DaveLomber Sent my app id to your support email now.

DaveLomber commented 4 years ago

Ok we just checked the logs

We see 3 requests with errors: 2 with '500 Internal Server Error' and one is with '401 Unauthorized'

all the rest obviously was ok

DaveLomber commented 4 years ago

@Jempan we also enabled additional logging Please repeat a couple of times the request and let us know We will check for more

Jempan commented 4 years ago

@DaveLomber Thanks a lot 🙏 Since I tested many different combinations both on my server and with your admin settings it's not surprising that you see some 500 and 401 errors. I just ran 2 request now again, one with the ConnectyCube.videochatconference.createNewSession() line added one without. I get the same behaviour described above 201 created but empty and Error: Session does not exist at ConferenceClient.getCurrentSessionToken. Hope you can see something helpful in your additional logs ✊

DaveLomber commented 4 years ago

@Jempan We do not see any wrong behaviour in logs

Could you please do us a favour and try 2 things:

1) disable custom identity provider and perform

ConnectyCube.createSession().then(session => {
   console.log(session)
})

is session is here?

2) and now enable again custom identity provider and try the same

Jempan commented 4 years ago

Hi again @DaveLomber! I tried to disable/enable custom identity provider and creating the session in all suggested different ways. Still the same problem, 201 session created but empty response. I also tried with your test credentials in the example app and finally ran the example app which gave me the same 201 session created but empty response problem as I have with my own app.

Then tried to run the example app without debugging in React Native Debugger and bam, that worked, the session was created and returned!! Even more specific it looks like your library does not work when Network Inspect in React Native Debugger is enabled.

stephanoparaskeva commented 4 years ago

What about using Refresh Tokens?

NeenaMishra12 commented 4 years ago

Hi @Jempan and @DaveLomber , I also need to implement ConnectyCube using our server user base and I am also trying to implement it by following below steps but, I am getting 401 as login response with ConnectyCube login and when tried with ConnectyCube.login() method I am getting 404 as Response status code:

Can you please suggest what could be a reason for that?

Steps I followed: (All in React-Native project)

  1. ConnectyCube.init(config)
  2. ConnectyCube.createSession() .then((session) => {}) .catch((error) => {});

Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', };

Response: {"id":15143047,"user_id":0,"application_id":XXXX,"nonce":8133,"token":"XXXXXXXXXXXXXXXXXXXXXXXXXX","ts":1594730932,"created_at":"2020-07-14T12:48:54Z","updated_at":"2020-07-14T12:48:54Z"}

  1. ConnectyCube.login() .then((user) => {}) .catch((error) => {});

Request Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', keys: { token:"XXXXXXXXXXXXXXXXXXXXXXXXXX" } }; //Token received from CreateSession Method

Response: Connecty cube user error {"code":404,"info":" "}

And when we used API to login it gives:

Request Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', keys: { token:"XXXXXXXXXXXXXXXXXXXXXXXXXX" } }; //Token received from CreateSession Method

Response: Request failed with code 401

As per the doc we should do this: POST https://api.connectycube.com/login login=IP_user_id //This we are getting as 0 from createSession response. password=IP_token

Note: But in our case we have used request params as we are not receiving user_id as 0 after creating session.

stephanoparaskeva commented 4 years ago

Hi! Following the instructions for external authentication via Custom Identity Provider at https://developers.connectycube.com/guides/custom-identity-provider but feel that some information is missing. The call to https://api.connectycube.com/login obviously requires a "token". Is it an application session token and if so how can I retrieve it? Trying to run:

ConnectyCube.init(config) ConnectyCube.createSession() .then((session) => {}) .catch((error) => {});

But I don't get any session information back. Guess I misunderstood something?

You are asking is it an application session token and asking about what the token is. Did you find the answer and if so, what was the answer, which token?

I see that in this diagram it shows that you receive a "token" from your backend:

Screenshot 2020-07-18 at 17 59 39

How do you get a "token" from your backend, my backend doesnt send any tokens and it's not explained...

ccvlad commented 4 years ago

Hi @Jempan and @DaveLomber , I also need to implement ConnectyCube using our server user base and I am also trying to implement it by following below steps but, I am getting 401 as login response with ConnectyCube login and when tried with ConnectyCube.login() method I am getting 404 as Response status code:

Can you please suggest what could be a reason for that?

Steps I followed: (All in React-Native project)

  1. ConnectyCube.init(config)
  2. ConnectyCube.createSession() .then((session) => {}) .catch((error) => {});

Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', };

Response: {"id":15143047,"user_id":0,"application_id":XXXX,"nonce":8133,"token":"XXXXXXXXXXXXXXXXXXXXXXXXXX","ts":1594730932,"created_at":"2020-07-14T12:48:54Z","updated_at":"2020-07-14T12:48:54Z"}

  1. ConnectyCube.login() .then((user) => {}) .catch((error) => {});

Request Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', keys: { token:"XXXXXXXXXXXXXXXXXXXXXXXXXX" } }; //Token received from CreateSession Method

Response: Connecty cube user error {"code":404,"info":" "}

And when we used API to login it gives:

Request Params: const userCredentials = { login: 'XXXXXX', password:'XXXXXX', keys: { token:"XXXXXXXXXXXXXXXXXXXXXXXXXX" } }; //Token received from CreateSession Method

Response: Request failed with code 401

As per the doc we should do this: POST https://api.connectycube.com/login login=IP_user_id //This we are getting as 0 from createSession response. password=IP_token

Note: But in our case we have used request params as we are not receiving user_id as 0 after creating session.

0) Authentication via external identity provider guide 1) ConnectyCube.createSession() to create an empty session (code snippet from guide) 2) Do login in your Backend and receives a token (or any data that can be used to confirm user auth on your BE) 3) Login to ConnectyCube with data received from your Backend - ConnectyCube.login(someLoginDataObject). The ConnectyCube API will request your BE (pointed in the ConnectyCube Admin panel) and would send your the session (with your user) after gets a successful verification from your BE.

ccvlad commented 4 years ago

How do you get a "token" from your backend, my backend doesnt send any tokens and it's not explained...

Any data to verify your user.

ccvlad commented 4 years ago

@NeenaMishra12 did everything work out or you still need help?