繁体   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