linkedin_login 1.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

linkedin_login #

Codacy Badge Codemagic build status

  • A Flutter library for LinkedIn OAuth 2.0 APIs .
  • This library is using new way of authorization on LinkedIn

⭐⭐⭐⭐ Star ⭐⭐⭐⭐ a repo if you like project. Your support matters to us.⭐⭐⭐⭐ #

Installation #

Important #

You should replace this values

final String redirectUrl = 'YOUR-REDIRECT-URL';
final String clientId = 'YOUR-CLIENT-ID';
final String clientSecret = 'YOUR-CLIENT-SECRET';

Note: clientSecret field is required just for LinkedInUserWidget

To get these values you need to create App on the LinkedIn.

Samples #

You can see full example under this project.

Call LinkedIn authorization and get user object:

    LinkedInUserWidget(
       redirectUrl: redirectUrl,
       clientId: clientId,
       clientSecret: clientSecret,
       onGetUserProfile:
           (LinkedInUserModel linkedInUser) {
                print('Access token ${linkedInUser.token.accessToken}');
                print('First name: ${linkedInUser.firstName.localized.label}');
                print('Last name: ${linkedInUser.lastName.localized.label}');
       },
       catchError: (LinkedInErrorObject error) {
         print(
             'Error description: ${error.description},'
             ' Error code: ${error.statusCode.toString()}');
        },
    )

Or you can just fetch authorization code (clientSecret is not required in this widget):

    LinkedInAuthCodeWidget(
        redirectUrl: redirectUrl,
        clientId: clientId,
        onGetAuthCode:
            (AuthorizationCodeResponse response) {
                print('Auth code ${response.code}');
                print('State: ${response.state}');
            },
    ),

If you want to logout user (to clear session from webview) all you need is to forward true value to property destroySession in LinkedInUserWidget or LinkedInAuthCodeWidget. Please don't forget to destroy your data in your local storage for this user. Currently, LinkedIn doesn't have API point on OAuth 2 which will destroy access token.

Properties that are available after call for LinkedInUserWidget #

  String firstName;
  String lastName;
  String accessToken;
  int expiresIn;
  String profilePicture;
  String email;
  String userId; (from version 0.1.)

Properties that are available after call for LinkedInAuthCodeWidget #

  String code; // authorization code
  String state;

Widgets #

Standard LinkedIn button for login. This widget is modifiable.

LinkedInButtonStandardWidget(onTap: () {});

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v0.1.0 - 2019-01-23 #

Added #

  • Login with LinkedIn support to Android and IOS using pure dart
  • LinkedIn default button
  • Retrieve basic user information from linked login with email and token

v0.1.1 - 2019-04-03 #

Version upgrade #

  • Upgrade version of libraries that this package is using

v0.1.3 - 2019-05-03 #

Added new field into user model #

  • UserId in LinkedInUserModel class
  • Fix bugs if there is not existing images

v0.1.4 - 2019-05-30 #

Added new widget - fetch only authorization code #

  • Fetch just authorization code
  • Use widget without sending client secret code

v0.1.6 - 2019-07-5 #

Added new widget - possibility to add custom app bar #

  • Add possibility to add app bar into webview as parameter

v0.1.7 - 2019-08-5 #

Add frontendRedirectUrl property in case of frontend redirection #

  • It can be case that URL route from redirect is redirecting to some other field
  • in that case you can use property "frontendRedirectUrl" so that you still can use redirect URL
  • of LinkedIn, but also handle if frontend redirect that link to some other site

v0.1.8 - 2019-08-5 #

Expose frontendRedirectUrl property #

  • Expose frontendRedirectUrl field

v0.2.0 - 2019-08-12 #

Possibility to clean cache and logout a user #

  • Possibility to log out user from linkedIn - from now you can change account as should

v1.0.0 - 2020-01-20 #

Support for web #

  • Added support for web
  • Update dependency versions

v1.1.0 - 2020-01-22 #

Change error parsing issue #

v1.1.1 - 2020-01-22 #

Version update to v1.1.1 #

  • Version updated

v1.1.2 - 2020-04-28 #

Fix #12 #

v1.1.3 - 2020-05-09 #

Resolve #23 #

  • Replace AppBar with PreferredSizeWidget. Thanks for contribution @ricardonior29

v1.1.5 - 2020-05-31 #

Version updated to v1.1.5 #

  • Replace AppBar with PreferredSizeWidget. Thanks for contribution @ricardonior29
  • Fix lint messages
  • Increase Dart SDK version

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:linkedin_login/linkedin_login.dart';

void main() => runApp(MyApp());

// @TODO IMPORTANT - you need to change variable values below
// You need to add your own data from LinkedIn application
// From: https://www.linkedin.com/developers/
// Please read step 1 from this link https://developer.linkedin.com/docs/oauth2
final String redirectUrl = 'https://app.carde.de';
final String clientId = '776rnw4e4izlvg';
final String clientSecret = 'rQEgboUHMLcQi59v';

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter LinkedIn demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(
                  icon: Icon(Icons.person),
                  text: 'Profile',
                ),
                Tab(icon: Icon(Icons.text_fields), text: 'Auth code')
              ],
            ),
            title: Text('LinkedIn Authorization'),
          ),
          body: TabBarView(
            children: [
              LinkedInProfileExamplePage(),
              LinkedInAuthCodeExamplePage(),
            ],
          ),
        ),
      ),
    );
  }
}

class LinkedInProfileExamplePage extends StatefulWidget {
  @override
  State createState() => _LinkedInProfileExamplePageState();
}

class _LinkedInProfileExamplePageState
    extends State<LinkedInProfileExamplePage> {
  UserObject user;
  bool logoutUser = false;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            LinkedInButtonStandardWidget(
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (BuildContext context) => LinkedInUserWidget(
                      appBar: AppBar(
                        title: Text('OAuth User'),
                      ),
                      destroySession: logoutUser,
                      redirectUrl: redirectUrl,
                      clientId: clientId,
                      clientSecret: clientSecret,
                      onGetUserProfile: (LinkedInUserModel linkedInUser) {
                        print('Access token ${linkedInUser.token.accessToken}');

                        print('User id: ${linkedInUser.userId}');

                        user = UserObject(
                          firstName: linkedInUser.firstName.localized.label,
                          lastName: linkedInUser.lastName.localized.label,
                          email: linkedInUser
                              .email.elements[0].handleDeep.emailAddress,
                        );
                        setState(() {
                          logoutUser = false;
                        });

                        Navigator.pop(context);
                      },
                      catchError: (LinkedInErrorObject error) {
                        print('Error description: ${error.description},'
                            ' Error code: ${error.statusCode.toString()}');
                        Navigator.pop(context);
                      },
                    ),
                    fullscreenDialog: true,
                  ),
                );
              },
            ),
            LinkedInButtonStandardWidget(
              onTap: () {
                setState(() {
                  user = null;
                  logoutUser = true;
                });
              },
              buttonText: 'Logout',
            ),
            Container(
              child: Column(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text('First: ${user?.firstName} '),
                  Text('Last: ${user?.lastName} '),
                  Text('Email: ${user?.email}'),
                ],
              ),
            ),
          ]),
    );
  }
}

class LinkedInAuthCodeExamplePage extends StatefulWidget {
  @override
  State createState() => _LinkedInAuthCodeExamplePageState();
}

class _LinkedInAuthCodeExamplePageState
    extends State<LinkedInAuthCodeExamplePage> {
  AuthCodeObject authorizationCode;
  bool logoutUser = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        LinkedInButtonStandardWidget(
          onTap: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (BuildContext context) => LinkedInAuthCodeWidget(
                  destroySession: logoutUser,
                  redirectUrl: redirectUrl,
                  clientId: clientId,
                  onGetAuthCode: (AuthorizationCodeResponse response) {
                    print('Auth code ${response.code}');

                    print('State: ${response.state}');

                    authorizationCode = AuthCodeObject(
                      code: response.code,
                      state: response.state,
                    );
                    setState(() {});

                    Navigator.pop(context);
                  },
                  catchError: (LinkedInErrorObject error) {
                    print('Error description: ${error.description},'
                        ' Error code: ${error.statusCode.toString()}');
                    Navigator.pop(context);
                  },
                ),
                fullscreenDialog: true,
              ),
            );
          },
        ),
        LinkedInButtonStandardWidget(
          onTap: () {
            setState(() {
              authorizationCode = null;
              logoutUser = true;
            });
          },
          buttonText: 'Logout user',
        ),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Auth code: ${authorizationCode?.code} '),
              Text('State: ${authorizationCode?.state} '),
            ],
          ),
        ),
      ],
    );
  }
}

class AuthCodeObject {
  String code, state;

  AuthCodeObject({this.code, this.state});
}

class UserObject {
  String firstName, lastName, email;

  UserObject({this.firstName, this.lastName, this.email});
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  linkedin_login: ^1.1.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:linkedin_login/linkedin_login.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:linkedin_login/linkedin_login.dart, package:linkedin_login/src/linked_in_auth_code.dart, package:linkedin_login/src/linked_in_auth_code_webview.dart, package:flutter_webview_plugin/flutter_webview_plugin.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:linkedin_login/linkedin_login.dart, package:linkedin_login/src/linked_in_auth_code.dart, package:linkedin_login/src/linked_in_auth_code_webview.dart, package:flutter_webview_plugin/flutter_webview_plugin.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:linkedin_login/linkedin_login.dart, package:linkedin_login/src/linked_in_auth_code.dart, package:linkedin_login/src/linked_in_auth_code_webview.dart, package:flutter_webview_plugin/flutter_webview_plugin.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:linkedin_login/linkedin_login.dart, package:linkedin_login/src/linked_in_auth_code.dart, package:linkedin_login/src/linked_in_auth_code_webview.dart, package:flutter_webview_plugin/flutter_webview_plugin.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [linkedin_login] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
flutter_webview_plugin ^0.3.10+1 0.3.11
http ^0.12.0+4 0.12.1
uuid ^2.0.4 2.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
http_parser 3.1.4
meta 1.1.8
path 1.7.0
pedantic 1.9.0 1.9.1
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test