Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth 2.0 integration in iOS

I have been trying for ages now to get OAuth 2.0 integration in my iPhone application.

I have searched and searched for libraries, tutorials, etc... But they have all lead me to a dead end. The main problem I have is that they either have deprecated code, or they just don't work or they have some documentation but its really hard to follow (for me anyway...).

The best OAuth2 library I could find for Xcode is this one: https://github.com/nxtbgthng/OAuth2Client

But the main problem with that one is it doesn't seem to do anything... I have followed all the documentation and instructions that came with it, but after building and running, it doesn't seem to authenticate....

So I guess my main question is: does anyone know of any good and up to date OAuth 2.0 tutorials for Xcode or any libraries for such a thing?

Because I am really struggling at the moment.... :(

Thanks for your time, Dan.

UPDATE 2: Here is my code (App Id and secret removed for security):

- (void)viewDidLoad {     [super viewDidLoad];     // Do any additional setup after loading the view, typically from a nib.  oauthClient = [[LROAuth2Client alloc]                initWithClientID:@"MY_CLIENT_ID"                secret:@"MY_APP_SECRET"                redirectURL:[NSURL URLWithString:@"app://instagram-callback/?code="]]; oauthClient.delegate = self;  oauthClient.userURL  = [NSURL URLWithString:@"https://api.instagram.com/oauth/authorize/?client_id=ab6dc96859bf43b3a488199ec72d9964&redirect_uri=app://instagram-callback/?code=&response_type=code"]; oauthClient.tokenURL = [NSURL URLWithString:@"https://api.instagram.com/oauth/access_token/"];   [oauthClient authorizeUsingWebView:myWebView];   }  - (void)oauthClientDidReceiveAccessToken:(LROAuth2Client *)client; {     LROAuth2AccessToken *token = client.accessToken;     [NSKeyedArchiver archiveRootObject:token toFile:@"Path/To/MyAccessToken"]; }  - (void)checkAccessTokenForExpiry:(LROAuth2AccessToken *)accessToken; {     if ([accessToken hasExpired]) {         [oauthClient refreshAccessToken:accessToken];     } }  - (void)oauthClientDidRefreshAccessToken:(LROAuth2Client *)client; {     LROAuth2AccessToken *token = client.accessToken;     [NSKeyedArchiver archiveRootObject:token toFile:@"Path/To/MyAccessToken"]; } 
like image 921
Supertecnoboff Avatar asked Aug 12 '13 17:08

Supertecnoboff


People also ask

What is OAuth2 in iOS?

OAuth2 lets users grant third-party apps access to their web resources, without sharing their passwords, through a security object known as an access token. It's impossible to obtain the password from the access token, since your password is kept safe inside the main service.

What is more iOS with new OAuth?

With the release of iOS 11.0, the native mail client has now support for OAuth 2.0. OAuth 2.0 is often mentioned as modern authentication and provides some new capabilities like Microsoft Azure Multi-factor Authentication support and allows to using certificates for authentications.

How does OAuth2 2.0 work in REST API?

In OAuth 2.0, the following three parties are involved: The user, who possesses data that is accessed through the API and wants to allow the application to access it. The application, which is to access the data through the API on the user's behalf. The API, which controls and enables access to the user's data.


1 Answers

In almost all projects I have used AFNetworking because it's very powerful -why re-invent the wheel every time :)

Furthermore, it also has an OAuth2Manager which is quite easy to implement and works rock-solid.

like image 121
dOM Avatar answered Oct 04 '22 06:10

dOM