簡體   English   中英

Linkedin iOS身份驗證要求啟動Linkedin應用

[英]Linkedin iOS Authentication requires launching of the Linkedin app

我在與iOS應用程序集成LinkedIn SDK時遇到問題。 似乎身份驗證過程要求我下載LinkedIn應用程序才能與LinkedIn連接。 有沒有一種方法可以使用sdk,而不必下載LinkedIn應用程序? 蘋果因此拒絕了該應用程序。 對於解決此問題的任何提示,我將不勝感激。 提前致謝

此頁面上日期為2015年11月6日的其他答案,均指iOS9之前的過程及其最新的SDK

對於最新版本,“必須”安裝移動應用程序才能使單點登錄過程正常工作。 工作流程為:

  • 用戶指示您的應用程序中的登錄過程
  • 您的應用程序利用了應用程序中鏈接的SSO流程
  • 登錄完成后,您會收到回調以繼續從上次中斷的地方繼續。

就iOS應用程序而言,這是利用SSO的“必需”方式。 但是,在移動版本和非移動版本的應用程序之間共享授權令牌時,有一些變通方法。

我分享了以下答案:
https://stackoverflow.com/a/34312931/1804181
https://stackoverflow.com/a/34451266/1804181
並且第一個答案的OP已成功實施了該解決方案。

簡單的說:

測試是否存在鏈接的應用程序:

  • 如果不存在:直接通過您的應用實現OAuth2
  • 如果有的話:使用它或您的OAuth2實施(您可能會在使用他們的應用程序時犯錯,因為您可能需要在應用程序的任何功能之間建立鏈接能力)。

從而避免了安裝該應用程序的要求,但如果已安裝則可以使用它。

在LinkedIn iOS SDK網站上,它要求用戶已經安裝了官方LinkedIn應用程序。 您可能可以使用將UIWebView嵌入到您的應用程序中,並使用OAuth2身份驗證流對用戶進行身份驗證並獲得必要的授權令牌。 您還可以使用canOpenURL來檢查用戶是否具有LinkedIn應用程序(iOS 9顯然改變了它的工作方式)並提示他們安裝該應用程序。 祝你好運

可以在這里找到有關將OAuth2登錄從本地ios應用集成到linkedin的非常好的博客文章: http : //www.oodlestechnologies.com/blogs/Linkedin-Integration-in-Native-iOS這有點過時了,但我希望幫助。

完整的工作代碼,無論是否安裝了LinkedIn App。

如果您在專案中使用cocoapod而不是-

pod 'IOSLinkedInAPI', '~> 2.0'

ViewController.h中添加這些Headers文件。

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

在您的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!");
}

在您的Linkedin應用設置頁面中添加上述URL。

授權的重定向URL: http:// linkedin_oauth / success

希望對您有幫助。

嘗試使用LIExplorer庫獲取linkedin身份驗證和REST API。 它易於使用。 https://github.com/vijayviswas/LIExplorer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM