LinkedIn-SDK-Android - A lightweight android library to implement Login with LinkedIn in your Android app.

Overview

LinkedIn-SDK-Android

Download

A lightweight android library to implement Login with LinkedIn in your Android app, that supports both Activities and Fragments.

Inspired by shantanu-deshmukh/LinkedIn-SDK-Android

Table of contents

Targeted use cases

This SDK was designed to be used to authenticate with LinkedIn mainly for two use cases:

  1. If you want only to retrieve a user's access token.
    • For example to be sent the a back end server via your own APIs for further processing and data fetching.
  2. If you want to get the user's lite profile.
    • For simpler login process and to get his user name and profile picture.

You can choose which one you best suits you, simply using the setAccessTokenRetrievalOnlyRequest(accessTokenRetrievalOnlyRequest: Boolean) method in LinkedInBuilder object.

For example:

LinkedInFromFragmentBuilder.getInstance(MainActivity.this)
    .setClientID(clientID)
    .setAccessTokenRetrievalOnlyRequest(true)
    .setClientSecret(clientSecret)
    .setRedirectURI(redirectUrl)
    .authenticate(LINKEDIN_REQUEST);

will only try to retrieve user access token while the following the try to get the lite profile as well

LinkedInFromFragmentBuilder.getInstance(MainActivity.this)
    .setClientID(clientID)
    .setAccessTokenRetrievalOnlyRequest(false)
    .setClientSecret(clientSecret)
    .setRedirectURI(redirectUrl)
    .authenticate(LINKEDIN_REQUEST);

This flag defaults to false for backward compatibility reasons.

Main changes over the original

  • Add support for usage from fragments.
  • Allow for access token only request.
  • Kotlin-lize the SDK since now Kotlin is the main dev language for Android.
  • Better error handling.

SDK Structure

The SDK follows the clean architecture principles, so it's mainly divided into use cases, data, presentation(MVVM) and ui layers. Each has its own package, with manual dependency injection system to inject them when needed.

Why this UnOfficial SDK?

Adding the SDK to your Project

Just add the dependency to your app level build.gradle file

dependencies {
    implementation 'com.AbdAllahAbdElFattah13:linkedinsdk:1.2.0'
}

If you are getting Failed to resolve ERROR, make sure that Jcenter repository is added to your project level build.gradle file. This is done by default in recent versions of Android Studio.

Usage

Authenticating

  1. Add internet permission to your AndroidManifest.xml file if it's not already added.
<uses-permission android:name="android.permission.INTERNET" />
  1. Initiate Login Request. (You might want to do this on click of a login button)

    • From within fragments:
    LinkedInFromFragmentBuilder.getInstance(MainActivity.this)
            .setClientID("<YOUR_CLIENT_ID_HERE>")
            .setClientSecret("<YOUR_CLIENT_SECRET_HERE>")
            .setRedirectURI("<YOUR_REDIRECT_URL_HERE>")
            .authenticate(LINKEDIN_REQUEST_CODE);
    • From within activities:
    LinkedInFromActivityBuilder.getInstance(MainActivity.this)
            .setClientID(Ε’"<YOUR_CLIENT_ID_HERE>")
            .setClientSecret("<YOUR_CLIENT_SECRET_HERE>")
            .setRedirectURI("<YOUR_REDIRECT_URL_HERE>")
            .authenticate(LINKEDIN_REQUEST_CODE);

You can download the official Sign In with LinkedIn button images from here

  1. Handling Result: the sdk returns LinkedInUser object which contains the result data.
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == LINKEDIN_REQUEST_CODE && data != null) {
            if (resultCode == RESULT_OK) {
                //Successfully signed in
                LinkedInUser user = data.getParcelableExtra("social_login");

                //acessing user info
                Log.i("LinkedInLogin", user.getFirstName());

            } else {

                if (data.getIntExtra("err_code", 0) == LinkedInBuilder.ERROR_USER_DENIED) {
                    //Handle : user denied access to account

                } else if (data.getIntExtra("err_code", 0) == LinkedInBuilder.ERROR_FAILED) {
                    
                    //Handle : Error in API : see logcat output for details
                    Log.e("LINKEDIN ERROR", data.getStringExtra("err_message"));
                }
            }
        }

    }

LinkedInUser Class

Return Method Description
String getId() Returns LinkedIn user ID
String getEmail() Returns users email (May return null)
String getFirstName() Returns first name of the user
String getLastName() Returns last name of the user
String getProfileUrl() Returns profile url of the user
String getAccessToken() Returns access token that can be used to retrive data later. You might want to store it for later use.
long getAccessTokenExpiry() Expiry timestamp of the access token in Millisecond.

Security

To protect against CSRF during authorization, the sdk uses a 16 character token by default. If you want to use your own CSRF token, then use the setState method of the LinkedInBuilder class.

  • From within fragments:
LinkedInFromFragmentBuilder.getInstance(MainActivity.this)
        .setClientID("<YOUR_CLIENT_ID_HERE>")
        .setClientSecret("<YOUR_CLIENT_SECRET_HERE>")
        .setRedirectURI("<YOUR_REDIRECT_URL_HERE>")
        .setState("<YOUR_CSRF_TOKEN_HERE>")
        .authenticate(LINKEDIN_REQUEST_CODE);
  • From within activities:
LinkedInFromActivityBuilder.getInstance(MainActivity.this)
        .setClientID("<YOUR_CLIENT_ID_HERE>")
        .setClientSecret("<YOUR_CLIENT_SECRET_HERE>")
        .setRedirectURI("<YOUR_REDIRECT_URL_HERE>")
        .setState("<YOUR_CSRF_TOKEN_HERE>")
        .authenticate(LINKEDIN_REQUEST_CODE);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

You might also like...
πŸ“²πŸ’¬ react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.
πŸ“²πŸ’¬ react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.

React Native Fontext react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in androi

Sample to show how to implement blur graphical tricks
Sample to show how to implement blur graphical tricks

BlurEffectForAndroidDesign Sample to show how to implement blur graphical tricks All the explanations could be found here: http://nicolaspomepuy.fr/?p

The goal of this assignment is to implement GameOfFifteen
The goal of this assignment is to implement GameOfFifteen

Game of Fifteen Demo The board for the game of Fifteen is filled randomly with numbers from 1 to 15 and one empty space. You can move the neighboring

Learning about architecture with implement TMDB Restful API

PopCorn Movie and Tv Show list application. Build for learning about architecture (maybe it's clean architecture, but i don't know it's clean or not.

Implement Text Recognition using MLKit in Jetpack Compose using Kotlin
Implement Text Recognition using MLKit in Jetpack Compose using Kotlin

Implement Text Recognition using MLKit in Jetpack Compose using Kotlin. The application is built using Kotlin Programming Language with Jetpack Compose Navigation.

This repo contains sample mobile apps that implement contributor design pattern

This repo contains sample mobile apps that implement contributor design pattern. This design pattern was evolved to establish clean contracts for the developers and partners in Teams Mobile code base

A lightweight, feature-rich wrapper for the Telegram Bot API, providing a handy Kotlin DSL to quickly build your bot.

Kotlin Telegram Bot Kotlin based wrapper over Telegram API. Current version of the Telegram Api: 6.0 Principles Annotations Magic. The basic interacti

Android-easy-permissions-kt - EasyPermissionsKt - A lightweight Android library that abstracts all runtime permission boilerplate code to simplify the system permissions managemen This is an Augmented Reality Android app that is made by using ARcore and Sceneform SDK. πŸ“Έ πŸŽ‰
This is an Augmented Reality Android app that is made by using ARcore and Sceneform SDK. πŸ“Έ πŸŽ‰

ARCore Furniture Sample Furniture Sample with Scenform SDK This is a Augmented Reality Android app which is made by using ARcore and Sceneform SDK. Au

Comments
Releases(v1.2.0)
Owner
AbdAllah Abd-El-fattah
AbdAllah Abd-El-fattah
πŸ“± Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.

Material NavigationView for Android ?? ?? Android Library to implement Rich, Beautiful Material Navigation View for your project with Material Design

Shreyas Patil 198 Dec 17, 2022
App made using Kotlin to retrieve data from an API and show in a recyclerview with Login and SignUp features

App made using Kotlin to retrieve data from an API and show in a recyclerview with Login and SignUp features.

Altair Wallace 1 Feb 17, 2022
Projeto de Prova Semestral. Aplicativo Android com login e registro utilizando Firebase Authentication e consumo de API com Retrofit.

Ocean-Tech-Android Projeto de Prova Semestral. Aplicativo Android com login e cadastro utilizando Firebase Authentication e consumo de API com Retrofi

Marcos Lopes da Silva Junior 0 Nov 28, 2021
FirebaseAuthentication - Login/Register Android Application using Firebase Authentication

FireBaseAuthentication This is a Firebase Authentication Application which will

Akshat Bhuhagal 6 Nov 27, 2022
A simple login and logout Android application written in Kotlin

A simple login and logout Android application written in Kotlin. It authorizes user using an api and shows profile screen.

Emre Uysal 4 Aug 2, 2022
Amazing Material Login effect

MaterialLogin The Animation effect: You can download the source code. Problems can give me a message, thank you! License Copyright 2016 fanrunqi Licen

leo 1.9k Dec 30, 2022
Implement Dog vs Cat Prediction Model in Android app

This project aims to classify the input image as either a dog or a cat image. The image input which you give to the system will be analyzed and the predicted result will be given as output. Machine learning algorithm [Convolutional Neural Networks] is used to classify the image.

Aditya deshmukh 6 Oct 27, 2021
Implement Webpage in Android App

This is the application for add a webpage in a android app and act like a browser

Ankit P Chandran 1 Oct 14, 2021
Happy-Birthday - Design and implement a single screen app that displays information

Happy Birthday Android App | Android Basics in Kotlin Course Solution code for t

Anas Tariq 1 Feb 6, 2022