Универсальная база знаний LMS Wisdom System Wisdom Tree MAIN My Profile

Авторизация для iOS на Objective-C

by #Alex Torrison
Документ: https://docs.google.com/document/d/17h4lLNh1x8o794MljZ8jS7WfPU48KgaxobYwa4loY3A/edit?usp=sharing
// LogIn
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {

NSLog(@"Logged in");

if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, email, birthday, bio"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *email = result[@"email"];
if (email) {
NSLog(@"TOKEN: %@ fetched user:%@ and Email : %@", [[FBSDKAccessToken currentAccessToken] tokenString], result, result[@"email"]);

[self setLoaderTo:YES];

[self.mess sendWithData:[Params APIfbLoginBody:email token:[[FBSDKAccessToken currentAccessToken] tokenString]] urlContinue:[Params APIfbLoginGet] type:@"fb_login"];
} else {
[self showAlert:NSLocalizedString(@"ALERT", nil) withMessage:@"Для вашего аккаунта вход через Facebook ограничен, используйте обычную форму входа"];
}
}
}];
}
}
}];


+(NSData *)APIfbLoginBody:(NSString*)login token:(NSString*)token{
NSData *result;
NSString *post = [NSString stringWithFormat: @"email=%@&token=%@&moow_api=1", login,token];
result = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
return result;
}

+(NSString *)APIfbLoginGet{
return @"/auth_api/check_social_login/facebook/";
}
// ------------------ >> Logout

+(NSString *) getHttpJsonLogout{
NSString *result = [NSString stringWithFormat:@"/auth/logout/"];
return result;
}


Важно отправлять основные cookie с запросами!
/auth_api/


check_login
POST email, password
JSON status, message


check_social_login (For Redirect)
header redirect or string


fb_oauth_link
link string


check_reg
POST email, password
JSON status, message


check_recovery
POST recovery_email
JSON status, message


update_user_data
POST name, phone, social_vk, social_fb, adv_info, img_code(base64) del_image(0,1) personal_activities(0,1) personal_contacts(0,1), sex, birth_date
FILES [img](not used), POST del_image
NOT USED: full_address, street, h_number, city, district, country, country_code, admin_area
JSON status, message


change_password
POST old_password, new_password, confirm_password, email
JSON status, message


get_user_info
JSON


get_user_info_debug
JSON + COOKIE


/auth/logout
Ничего не возвращает - меняет куки, выполняет логаут!




Этот объект часть других / Parent