Linkedin iOS Authentication requires launching of

2020-02-15 22:00发布

问题:

I have a problem integrating LinkedIn sdk with my iOS app. It seems that the authentication process requires that I download the LinkedIn app to connect with LinkedIn. Is there a way to use the sdk without having to download the LinkedIn app? Apple rejects the app for that reason. I'd greatly appreciate any hints to work around this issue. Thanks in advance

回答1:

The other answers on this page that are dated the 6th of November 2015, each refer to processes prior to iOS9 and their latest SDKs.

With their latest version, it is a "requirement" that the mobile application be installed for the single sign on process to work. Workflow being:

  • user indicates login process in your app
  • your app utilises the linked in apps SSO process
  • you receive a callback to continue where you left off once the signon is complete.

In as far as the iOS application is concerned, this is the "required" way to utilise SSO. However, there is a slight workaround in sharing the authorisation token between the mobile and non-mobile versions of the app.

I have shared this in answers to:
https://stackoverflow.com/a/34312931/1804181 and
https://stackoverflow.com/a/34451266/1804181
and the OP of the first answer has successfully implemented this solution.

Simply put:

Test for the presence of the linked-in app:

  • if it is not there: implement OAuth2 directly through your app
  • if it is there: use it or your OAuth2 implementation (which you'd probably err on the side of using their app for the link-ability between any features of the app you may need in yours).

Thereby avoiding the REQUIREMENT to have the app installed, but utilising it if it is.



回答2:

On the LinkedIn iOS SDK website, it says that it requires the user to already have the official LinkedIn app installed. You may be able to use embed a UIWebView into your app and use the OAuth2 authentication flow to authenticate the user and get the authorization token necessary. You could also use canOpenURL to check if the user has the LinkedIn app (iOS 9 has changed how this works a little apparently) and prompt them to install the app. Best of luck,



回答3:

A really good blog post on integrating OAuth2 login to linkedin from a native ios app can be found here: http://www.oodlestechnologies.com/blogs/Linkedin-Integration-in-Native-iOS It's a little dated but I hope this helps.



回答4:

Here is demo in that LinkedIn authentication work inside app



回答5:

Try LIExplorer library for linkedin authentication and REST API. Its easy to use. https://github.com/vijayviswas/LIExplorer



回答6:

Complete working code whether LinkedIn App install or not.

If you are using cocoapod in your project than use -

pod 'IOSLinkedInAPI', '~> 2.0'

Inside your ViewController.h add these Headers files.

#import <linkedin-sdk/LISDK.h>
#import <LIALinkedInHttpClient.h>
#import <LIALinkedInApplication.h>
#import <AFHTTPRequestOperation.h>
@property (nonatomic, strong) LIALinkedInHttpClient *client;

Inside Your ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
  _client = [self client];
    }

    //ADD THESE METHOD

- (void)requestMeWithToken:(NSString *)accessToken 
    {
        [self.client GET:[NSString             stringWithFormat:@"https://api.linkedin.com/v1/people/~:(id,first-name,last-       name,maiden-name,email-address,formatted-name,phonetic-last-name,location:(country:(code)),industry,distance,current-status,current-share,network,skills,phone-numbers,date-of-birth,main-address,positions:(title),educations:(school-name,field-of-study,start-date,end-date,degree,activities))?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result){

    NSLog(@"current user %@", result);

    }failure:^(AFHTTPRequestOperation *operation, NSError *error){

    NSLog(@"failed to fetch current user %@", error);
    }];
}

    - (LIALinkedInHttpClient *)client {
    LIALinkedInApplication *application = [LIALinkedInApplication     applicationWithRedirectURL:@"http://linkedin_oauth/success"     clientId:LINKEDIN_CLIENT_ID clientSecret:LINKEDIN_CLIENT_SECRET     state:@"760iz0bjh9gy71asfFqa" grantedAccess:@[@"r_basicprofile",     @"r_emailaddress"]];

        return [LIALinkedInHttpClient clientForApplication:application         presentingViewController:self.navigationController];
    }


- (void)loginWithLinkedin
 {

[self.client getAuthorizationCode:^(NSString *code)
 {
    [self.client getAccessToken:code success:^(NSDictionary *accessTokenData)     {
        NSString *accessToken = [accessTokenData         objectForKey:@"access_token"];
        [self requestMeWithToken:accessToken];
    }                   failure:^(NSError *error) {
        NSLog(@"Querying accessToken failed %@", error);
    }];
}                      cancel:^{
    NSLog(@"Authorization was cancelled by user");
}                     failure:^(NSError *error) {
    NSLog(@"Authorization failed %@", error);
}];

 // While Using Linkedin iOS SDK or add if-else to check the app installed or not
    [LISDKSessionManager
 createSessionWithAuth:[NSArray     arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil]
 state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState)
 {
     NSLog(@"%s","success called!");
     LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
 }
 errorBlock:^(NSError *error){
     NSLog(@"%s","error called!");
}

Add the above URL in your Linkedin App setting Page.

Authorized Redirect URLs: http://linkedin_oauth/success

I hope it helps for you guys.