由于工作限制,必须部分使用Quickblox的RESTful API而不是iOS SDK。必须在不知道QuickBlox用户密码的情况下登录。对于移动应用程序也存在服务器版本在iOS QuickBlox SDK中,我只看到facebook或twitter,没有自定义https://sdk.quickblox.com/ios/documentation/sdk/Categories/QBRequest+QBAuth.html#//api/name/logInWithSocialProvider:accessToken:accessTokenSecret:successBlock:errorBlock :.
是否可以在不知道密码的情况下登录QuickBlox?
我在参数中添加了用户[登录](在此参数中我有电子邮件)并按照本文How to get QuickBlox token in Objective-C的第一篇文章进行请求。在QuickBlox SDK中,我没有找到令牌。
根据文档给出了状态201的服务器的成功响应 - 它也给了我。但是user_id = 0。 它将被创建会话,我得到令牌。我编辑了“application_id”:XXXXX到XXXXX,服务器给我真实的数据。 检查令牌的下一步操作是好还是不 - 通过2种方法登录 - 未授权401响应。
我如何在下次需要时使用令牌?
为什么要给user_id = 0?
我做错了什么?
可能是使用REST和QuickBlox iOS SDK的混合方法,例如创建会话或logIn by token,并将此会话设置为iOS SDK库 - QMChatViewController,QMServices,Quickblox-WebRTC?
NSMutableDictionary *parameters = [NSMutableDictionary
dictionary];
[parameters setValue:[NSString stringWithFormat:@"%lu",(unsigned long)appID] forKey:@"application_id"];
[parameters setValue:authKey forKey:@"auth_key"];
[parameters setValue:[NSString stringWithFormat:@"%lu",(unsigned long)nonce] forKey:@"nonce"];
[parameters setValue:[NSString stringWithFormat:@"%lu",(unsigned long)timestamp] forKey:@"timestamp"];
[parameters setValue:email forKey:@"user[login]"];
NSString *sig = [self signData:[self rawBodyWithoutEncode:parameters] withSecret:sekret];
// Package authentication data into JSON
NSDictionary *dict = @{
@"application_id":[NSString stringWithFormat:@"%lu", (unsigned long)appID],
@"auth_key":authKey,
@"nonce":[NSString stringWithFormat:@"%lu", (unsigned long)nonce],
@"timestamp":[NSString stringWithFormat:@"%lu", (unsigned long)timestamp],
@"signature":sig,
@"user[login]":email,
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:0
error:&error];
NSLog(@"%s: jsonString: %@", __FUNCTION__, [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]);
// Generate request
NSURL *url = [NSURL URLWithString:@"https://api.quickblox.com/session.json"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
// Headers
[request setHTTPMethod:@"POST"];
[request setValue:@"0.1.1" forHTTPHeaderField:@"QuickBlox-REST-API-Version"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *length = [NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]];
[request setValue:length forHTTPHeaderField:@"Content-Length"];
// Body
[request setHTTPBody:jsonData];
// Make call
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *dataResponseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%s: response: %@ data: %@ connectionError: %@", __FUNCTION__, response, dataResponseString, connectionError);
NSString *password = [QBSession currentSession].sessionDetails.token;
NSLog(@"password = %@",password);
// NSString *password1 = [QBBaseModule sharedModule].token;
[QBRequest logInWithUserLogin:email password:password successBlock:^(QBResponse *response, QBUUser *user) {
NSLog(@"logInWithUserLogin response = %@, user = %@",response, user);
} errorBlock:^(QBResponse *response) {
NSLog(@"logInWithUserLogin error response = %@",response);
}];
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
[QBRequest logInWithUserLogin:email password:[[json objectForKey:@"session"] objectForKey:@"token"] successBlock:^(QBResponse *response, QBUUser *user) {
NSLog(@"2 logInWithUserLogin response = %@, user = %@",response, user);
} errorBlock:^(QBResponse *response) {
NSLog(@"2 logInWithUserLogin error response = %@",response);
}];
}];
它从服务器登录
response: <NSHTTPURLResponse: 0x16e68e70> { URL: https://api.quickblox.com/session.json } { status code: 201, headers {
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Length" = 257;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sat, 04 Jun 2016 12:32:20 GMT";
Etag = "\"3d96a2460db32532039e9affe08a6320\"";
"QB-Token-ExpirationDate" = "2016-06-04 14:32:20 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.8.1";
Status = "201 Created";
"Strict-Transport-Security" = "max-age=15768000;";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 192027ebe9d9c17c32af5827b419b800;
"X-Runtime" = "0.014884";
"X-UA-Compatible" = "IE=Edge,chrome=1";
} } data: {"session":"_id":"5752ca54a28f9ac35900000c","application_id”:XXXXX,”created_at":"2016-06-04T12:32:20Z","device_id":0,"nonce":866,"token":"62a6d1f1c12fd52561d9f86f2599666756bdbf8f","ts":1465043526,"updated_at":"2016-06-04T12:32:20Z","user_id":0,"id":22817}} connectionError: (null)
2016-06-04 15:32:20.395 test[3295:1366011] password = 9967a14ffbef25355042d4b7b3896a95349b5227
[QBCore] Response error reasons: {
errors = (
Unauthorized
);
}
[QBCore] Response error reasons: {
errors = (
Unauthorized
);
}