Skip to content

A library written in Swift for managing OAuth2 authentication flows with LinkedIn without having to have the LinkedIn app installed.

License

Notifications You must be signed in to change notification settings

gabrielvincent/LinkedInAuth-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkedInAuth Swift

Carthage compatible

A library written in Swift for authenticating with LinkedIn using OAuth2.

The LinkedIn iOS SDK is broken by default because it forces the user to have the LinkedIn app installed on their device. This library abstracts the authentication flow using LinkedIn's OAuth2 API in an embeded WKWebView within the app.

Installation

Carthage

Add the following line to your Cartfile:

github "gabrielvincent/LinkedInAuth-Swift"

Usage

A sample app is available at https://github.com/gabrielvincent/LinkedInAuth-SampleApp

Make sure you have an app created in you LinkedIn developer account (https://www.linkedin.com/developers/apps). There you'll be able to get your client id, client secret and set the redirect URI.

First, create a configuration object:

let liAuthConfiguration = LinkedInAuthConfiguration(WithClientID: "YOUR_LINKEDIN_CLIENT_ID",
                                                    clientSecret: "YOUR_LINKEDIN_CLIENT_SECRET",
                                                    redirectURI: "https://your_redirect_uri.com",
                                                    scope: [.BasicProfile, .EmailAddress],
                                                    state: nil)

Then, use those configurations to begin the authentication flow:

LinkedInAuth.manager.authenticate(WithConfiguration: liAuthConfiguration, success: { (accessToken) in
            
    print("Did get access token: \(accessToken)")
    
    // Now you can use this access token to make API calls.
    
}) { (error) in
    
    print("Didn't get access token: \(error.localizedDescription)")
}

A UIViewController will be presented modally containing the WKWebView that will handle the authentication flow:

LinkedIn authentication dialog screenshot

Redirect URI

This library doesn't require a working URI endpoint in order to get the authorization code returned after the user authorizes your app. The authorization code is captured by the WKWebView instance presenting the authentication dialog. Still, a valid URI is required by LinkedIn.

About

A library written in Swift for managing OAuth2 authentication flows with LinkedIn without having to have the LinkedIn app installed.

Resources

License

Stars

Watchers

Forks

Packages

No packages published