PHP serverida iPhone ilovasidan foydalanuvchini autentifikatsiya qilish uchun yaxshi echim

IPhone ilovasi uchun xavfsiz foydalanuvchi identifikatsiyasini amalga oshirishga harakat qilaman. Men juda ko'p yangi odamman. Ko'p kodli qismlar va turli xil yo'llar bo'yicha takliflarni ko'rdim, ba'zilari esa tarixga o'xshash edi. Ushbu stsenariyda qanday yaxshi variant bo'lishi mumkin? JSON? ASIHTTPRequest?

Xullas, men bu uchun to'g'ri echim topa olmadim. Turli fikrlarni birlashtiradigan va o'z ehtiyojlarimga mos keladigan echimlarni topishga biroz qiyin. Agar kimdir namuna kodini baham ko'rsa yoki hech bo'lmasa meni biror joyga joylashtiradigan yechimga yo'naltirsa yaxshi bo'lardi. Oldindan rahmat.

Toni

0

2 javoblar

Serverda qanday foydalanuvchi identifikatori mavjud? Autentifikatsiya qilish uchun asosiy auth-ni ishlatishingiz mumkin, bu Vakolat sarlavhalarini o'z ichiga oladi.

ASIHTTPRequest has functionality enabling basic auth and even presenting a login dialog, if you're OK with using that (the project's just been discontinued).

You would obviously need to implement basic authentication on your server as well.

1
qo'shib qo'ydi
Agar siz ASIHTTPRequest foydalanayotgan bo'lsangiz, siz faqatgina [so'rovlar to'plamiUsername: @ "foo"] va [request setPassword: @ "bar"] dan foydalanib hisobga olish ma'lumotlarini belgilashingiz kerak. Va agar ularning ichki autentifikatsiyasi dialogini ishlatmoqchi bo'lsangiz, faqat [request setShouldPresentAuthenticationDialog: YES] -ni tanlang. Agar siz boshqa bir tizimni ishlatayotgan bo'lsangiz, kod [ehtimol addRequestHeader: @ "Yetkilendirme" qiymati: @ "kodlangan yetkilendirme dizesi"] uchun juda o'xshash bo'lishi mumkin.
qo'shib qo'ydi muallif Kristofer Sommestad, manba
Sizning javobingiz uchun rahmat. Serverda menda nazorat mavjud. Menga asosan "POST" dan foydalanib autentifikatsiya qilish kerak. Menobjective-cuchun juda yangiman, shuning uchun har qanday namunaviy kod juda yaxshi yordam beradi. So'rov (NSData, NSDictionary) tuzilgan qismga kerak.
qo'shib qo'ydi muallif Tony P V, manba

Men buni iOS ilovasidan uzoq PHP-server bilan muvaffaqiyatli autentifikatsiya qilish uchun ishlatganman. Bir oz kechikkan, lekin u kimgadir yordam berishi mumkin:

-(void)saveNewUserDetails{
    [[NSUserDefaults standardUserDefaults] setObject:self.username.text forKey:@"userName"];
    [SSKeychain setPassword:self.pwd.text forService:@"MiniCEXReporting" account:self.username.text]; //store securely rather than in NSUserDefaults
    [[NSUserDefaults standardUserDefaults] synchronize];

}

-(void) makeConnection{
    self.activityIndicator.hidden=NO;
    [self.activityIndicator startAnimating];

    receivedData=[[NSMutableData alloc] init];

    NSString *userString=self.username.text;
    postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://someURLhereWithUsernameappended/%@", userString]]];

    //for the real thing
    //postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://somsis-dev.leeds.ac.uk/api/minicex/%@", self.username.text]]];

    [postRequest setHTTPMethod:@"POST"];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:postRequest delegate:self];
    [connection start];    
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge previousFailureCount] == 0) {
        NSLog(@"received authentication challenge");
        NSURLCredential *newCredential = [NSURLCredential credentialWithUser:self.username.text
                                                                    password:self.pwd.text
                                                                 persistence:NSURLCredentialPersistenceForSession];
        NSLog(@"credential created");
        [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        NSLog(@"responded to authentication challenge");
    }
    else {
        NSLog(@"authentication failure username -%@- with password -%@-", self.username.text, self.pwd.text);
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication Error"
                                                        message:@"Please check your username and password"
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
        [alert show];
        [self.activityIndicator stopAnimating];
        self.activityIndicator.hidden=YES;
    }
}
0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb