Comments (13)
@asongkai just use 'token' as a password for the user. For it before call _loginToCubeChat(context, cubeUser);
do
// get current ConnectyCube session token and set as user's password
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
More detail in our documentation.
from connectycube-flutter-samples.
Thank you for response!
I'm not sure what is really happening, I do as mentioned but still not able to login
Error Log:
I/flutter (26426): CB-SDK: : *********************************************************
I/flutter (26426): *** RESPONSE *** 201 *** 916d7423-9bfd-4bf4-a8e2-58d1804d958d ***
I/flutter (26426): HEADERS
I/flutter (26426): {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=39641ae6a6e83b9b4e66cc7f5d81667c--201; path=/; max-age=5; HttpOnly; secure, status: 201 Created, transfer-encoding: chunked, date: Sat, 17 Oct 2020 00:00:15 GMT, access-control-allow-origin: *, strict-transport-security: max-age=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: d60d5eff-7339-448f-b808-aeea4efe4233, cb-token-expirationdate: 2020-10-17 02:00:14 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.021856, etag: W/"4fe0f78a28b91bcaf0814758c1a9a247", x-frame-options: SAMEORIGIN, x-content-type-options: nosniff}
I/flutter (26426): BODY
I/flutter (26426): {"session":{"id":18343448,"user_id":0,"application_id":3472,"nonce":3161826250,"token":"f6181faa591cd70390b1ec045e84bffc9d000d90","ts":1602892815,"created_at":"2020-10-17T00:00:15Z","updated_at":"2020-10-17T00:00:15Z"}}
I/flutter (26426):
I/flutter (26426): CB-SDK: : =========================================================
I/flutter (26426): === REQUEST ==== e1f408f2-a527-4e33-84a1-1406265f2dac ===
I/flutter (26426): REQUEST
I/flutter (26426): POST https://api.connectycube.com/session
I/flutter (26426): HEADERS
I/flutter (26426): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.5.0, CB-Token: f6181faa591cd70390b1ec045e84bffc9d000d90}
I/flutter (26426): BODY
I/flutter (26426): {"application_id":"3472","auth_key":"2SQ7ewuGSdVvA6f","nonce":"292839984","timestamp":"1602892816","signature":"73c0466a899148858b870c070863b2f20908c66c","user":{"login":"8562096729763","password":"f6181faa591cd70390b1ec045e84bffc9d000d90"}}
I/flutter (26426):
I/flutter (26426): CB-SDK: : *********************************************************
I/flutter (26426): *** RESPONSE *** 401 *** e1f408f2-a527-4e33-84a1-1406265f2dac ***
I/flutter (26426): HEADERS
I/flutter (26426): {connection: keep-alive, set-cookie: _mkra_ctxt=475cb6b3cf998eb82441327fa0736d57--401; path=/; max-age=5; HttpOnly; secure, cache-control: no-cache, status: 401 Unauthorized, transfer-encoding: chunked, date: Sat, 17 Oct 2020 00:00:17 GMT, access-control-allow-origin: *, strict-transport-security: max-age=31536000, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: 97591e6f-dd31-495b-8484-c8475e308719, connectycube-rest-api-version: 0.1.1, x-runtime: 0.025420, x-frame-options: SAMEORIGIN, x-content-type-options: nosniff}
I/flutter (26426): BODY
I/flutter (26426): {"errors":["Unauthorized"]}
I/flutter (26426):
I/flutter (26426): CB-SDK: LoginScreen.BodyState: Login error ResponseException: 401: {"errors":["Unauthorized"]}
Updated Code:
createSession()
.then((cubeSession) {
CubeUser cubeUser = CubeUser(
id: G.loggedInUser.id,
login: G.loggedInUser.phone,
password: CubeSessionManager.instance.activeSession?.token,
email: G.loggedInUser.email,
fullName: G.loggedInUser.name,
phone: G.loggedInUser.phone);
if (CubeSessionManager.instance.isActiveSessionValid()) {
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
_loginToCubeChat(context, cubeUser);
} else {
createSession(cubeUser).then((cubeSession) {
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
_loginToCubeChat(context, cubeUser);
}).catchError(_processLoginError);
}
})
.catchError((error) {});
from connectycube-flutter-samples.
You misunderstood me, you have to use the token as a password only for chat connection, not everywhere. It means you have to authorize via Firebase phone auth first, then use this token for chat login.
from connectycube-flutter-samples.
Hi,
I used the following code it works but I have another question,
loginToChat() async {
createSession()
.then((cubeSession) async {
CubeUser cubeUser = CubeUser(
id: G.loggedInUser.id,
login: G.loggedInUser.phone,
password: CubeSessionManager.instance.activeSession?.token,
email: G.loggedInUser.email,
fullName: G.loggedInUser.name,
phone: G.loggedInUser.phone);
if (CubeSessionManager.instance.isActiveSessionValid()) {
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
print('Token valid');
print(cubeUser.toJson());
_loginToCubeChat(context, cubeUser);
} else {
print('Token invalid');
String accessToken = await FirebaseAuth.instance.currentUser.getIdToken(true);
signInUsingFirebase(PROJECT_ID, accessToken)
.then((cubeUser) async {
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
print('password: $token');
createSession(cubeUser).then((cubeSession) {
_loginToCubeChat(context, cubeUser);
}).catchError(_processLoginError);
})
.catchError((error){
print(error);
});
}
})
.catchError((error) {});
}
Do I need to create a new Session token and login to chat every time the app open? or Connectycube manage the session like Firebase instance?
because I tried to put them in separate method only response like "unauthenticate", "session invalid".
from connectycube-flutter-samples.
No, in the current realisation of our Flutter SDK we don't have an automatic session management, you have to realise it by yourself.
from connectycube-flutter-samples.
As I mentioned above once I can login and created the user session if I close the app and reopen the session has gone which can't use other feature like chat or video call that's force me to login every time I open my app and the process of logging in is so slow too which make my app load slow at the start.
from connectycube-flutter-samples.
The demo app also same if I close the app and reopen the session has gone the same, need to select a user again and login again
So, once I authenticated with firebase and I try to create the user session token in a separate thread it only show me "Unauthorized" message on response so the solution for my case now is like I posted the code above
I mentioned firebase instance because "Yes, I have to do the user session by myself in order to redirect user to login or home screen" but I don't have to authenticate again or login again to be able to use the chat or video feature.
but current case is once I logged in I can use but if I close the app and reopen and go to use chat or video it said "Unauthenticated"
from connectycube-flutter-samples.
As I said before, the current version of our SDK doesn't have a session manager yet and you can realize it by yourself.
There can be oriented steps:
- save needed session data (session, token expiration date, login, password, auth token, etc) to secure storage;
- before performing any request, check if the session expired, need to create a new with saved data, then perform request;
- if the saved session not expired, just set the saved session to SDK via
CubeSessionManager.instance.activeSession = session;
, then perform needed requests.
from connectycube-flutter-samples.
Thank you very much I will give that try
from connectycube-flutter-samples.
Hi,
I do as you mentioned by why the token expiry date is always null
String accessToken =
await FirebaseAuth.instance.currentUser.getIdToken(true);
signInUsingFirebase(PROJECT_ID, accessToken).then((cubeUser) async {
String token = CubeSessionManager.instance.activeSession?.token;
cubeUser.password = token;
createSession(cubeUser).then((cubeSession) {
services.setValue('token', cubeSession.token);
services.setValue('token_expire', cubeSession.tokenExpirationDate);
print('token_token: ${cubeSession.token}');
print('token_expire: ${cubeSession.tokenExpirationDate}');
_loginToCubeChat(context, cubeUser);
}).catchError(_processLoginError);
}).catchError((error) {
print(error);
});
What's wrong?
from connectycube-flutter-samples.
why the token expiry date is always null
we found the issue on the SDK side, we will provide fixes in the next release, thank you for your checks.
from connectycube-flutter-samples.
@asongkai today we released version 0.5.1 with required fixes for your issue.
But pay attention, you should use this way for getting the expiration date CubeSessionManager.instance.getTokenExpirationDate();
because any successful API request prolongs the token validity for 2 hours. More in our documentation for server API.
from connectycube-flutter-samples.
Closing. If you have a similar issue in the latest version, please create a new ticket with a description according to templates.
from connectycube-flutter-samples.
Related Issues (20)
- User Session Times Out and doesn't reconnect HOT 1
- Issue with ConnectyCube User Session Token Creation - "Unexpected Signature" HOT 23
- When internet is slow, getting a timeout log but not getting a callback HOT 5
- Cannot create chat group with more than 30 people HOT 4
- Notifications send to all attendees [even the host] HOT 2
- Reject call from notifications not ending the call for the other opponent HOT 23
- Notifications and incoming call screen appear on the same time, when the app is open. HOT 11
- Declining the call from the push notifications while the app is killed it doesnโt send an event to the other participant HOT 28
- Call notifications is not showing HOT 1
- Cannot receive message from multiple accounts login different session same device HOT 2
- [iOS] p2p_call_sample won't build using latest Flutter HOT 4
- Wrong primary video rendered on the video call HOT 6
- VOIP not working in IOS Terminated State and No call log preview in Phone App (IOS)
- Join directly on calls or Re-join or establish calls when participant session drops suddenly HOT 10
- Got troubles with building Flutter code samples.Can anybody help me create a simple sample for p2p calls HOT 3
- Null check operator on P2PClient.init HOT 5
- Intermittent issues in conference calls HOT 1
- Mute audio on conference video call [iOS only] not working HOT 6
- Hang up exception block the session from start [ [DTLS alert], error object is [Instance of 'WsHangUpException']] HOT 8
- Issues in video calls HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connectycube-flutter-samples.