linkedin_openid_login 2.3.3
linkedin_openid_login: ^2.3.3 copied to clipboard
Library for Sign In with LinkedIn using OpenID Connect. This library helps you to implement authorization with LinkedIn OAuth API's.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:linkedin_openid_login/linkedin_openid_login.dart';
// ignore_for_file: avoid_print
void main() => runApp(const 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
// const String redirectUrl = 'https://www.youtube.com/callback';
const String redirectUrl =
'https://www.linkedin.com/developers/tools/oauth/redirect';
const String clientId = '';
const String clientSecret = '';
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(final BuildContext context) {
return MaterialApp(
title: 'Flutter LinkedIn demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: const Text('LinkedIn Authorization Demo'),
),
body: const LinkedInProfileExamplePage(),
),
),
);
}
}
class LinkedInProfileExamplePage extends StatefulWidget {
const LinkedInProfileExamplePage({super.key});
@override
State createState() => _LinkedInProfileExamplePageState();
}
class _LinkedInProfileExamplePageState
extends State<LinkedInProfileExamplePage> {
UserObject? user;
bool logoutUser = false;
@override
Widget build(final BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
...(user == null
? [
LinkedInButtonStandardWidget(
onTap: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (final BuildContext context) =>
LinkedInUserWidget(
appBar: AppBar(
title: const Text('OAuth User'),
),
destroySession: logoutUser,
redirectUrl: redirectUrl,
clientId: clientId,
clientSecret: clientSecret,
projection: const [
ProjectionParameters.id,
ProjectionParameters.localizedFirstName,
ProjectionParameters.localizedLastName,
ProjectionParameters.firstName,
ProjectionParameters.lastName,
ProjectionParameters.profilePicture,
],
scope: const [
EmailAddressScope(),
LiteProfileScope(),
],
onError: (final UserFailedAction e) {
print('Error: ${e.toString()}');
print('Error: ${e.stackTrace.toString()}');
},
onGetUserProfile:
(final UserSucceededAction linkedInUser) {
// print(
// 'MJM Access token ${linkedInUser.user.token.accessToken}',
// );
user = UserObject(
firstName: linkedInUser.user.firstName,
lastName: linkedInUser.user.lastName,
email: linkedInUser.user.email,
profileImageUrl: linkedInUser.user.picture,
fullName: linkedInUser.user.name,
);
setState(() {
logoutUser = false;
});
Navigator.pop(context);
},
),
fullscreenDialog: true,
),
);
},
),
]
: [
Image.network(
user?.profileImageUrl ??
'https://beforeigosolutions.com/wp-content/uploads/2021/12/dummy-profile-pic-300x300-1.png',
height: 100,
width: 100,
fit: BoxFit.contain,
),
const SizedBox(height: 8),
Text('Name: ${user?.fullName} '),
Text('Given Name: ${user?.firstName} '),
Text('Family Name: ${user?.lastName} '),
Text('Email: ${user?.email}'),
const SizedBox(height: 15),
LinkedInButtonStandardWidget(
onTap: () {
setState(() {
user = null;
logoutUser = true;
});
},
buttonText: 'Logout',
),
])
],
),
);
}
}
class UserObject {
UserObject({
required this.firstName,
required this.lastName,
required this.email,
required this.profileImageUrl,
required this.fullName,
});
final String? firstName;
final String? lastName;
final String? email;
final String? profileImageUrl;
final String? fullName;
}