Updated 7 December 2023
In this blog, we are going to learn about “LinkedIn Login” in a flutter.
OAuth 2.0 is used by LinkedIn, the largest and most reliable source of professional identities, for API authentication and user permission. An access token is made available after successful login and can be used to retrieve member profiles and emails.
I’ll show you how to set up LinkedIn sign-in on your Flutter and retrieve pertinent data using the LinkedIn API in this tutorial.
sign in using Linkedin
Check out more about our Flutter app development.
The Dependency Section mentions, that these libraries to use the most recent version of the package
1 |
linkedin_login: ^2.2.1 |
The below command runs in the terminal of the Android studio after adding the dependency.
1 |
flutter pub add linkedin_login |
Get clientId and clientSecret when creating an app on https://www.linkedin.com/developers/apps/new for the authentication procedure.
1 2 3 |
<strong>final</strong> <strong>String</strong> redirectUrl = 'YOUR-REDIRECT-URL'; <strong>final</strong> <strong>String</strong> clientId = 'YOUR-CLIENT-ID'; <strong>final</strong> <strong>String</strong> clientSecret = 'YOUR-CLIENT-SECRET'; |
After the completed process we are adding the Call LinkedIn authorization and get the user object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
LinkedInUserWidget( redirectUrl: redirectUrl, clientId: clientId, clientSecret: clientSecret, onGetUserProfile: (UserSucceededAction linkedInUser) { print('Access token ${linkedInUser.user.token.accessToken}'); print('First name: ${linkedInUser.user.firstName.localized.label}'); print('Last name: ${linkedInUser.user.lastName.localized.label}'); }, onError: (UserFailedAction e) { print('Error: ${e.toString()}'); }, ) |
Alternatively, you can just retrieve the permission code (clientSecret is not necessary for this widget)
1 2 3 4 5 6 7 8 9 10 11 12 |
LinkedInAuthCodeWidget( redirectUrl: redirectUrl, clientId: clientId, onGetAuthCode: (AuthorizationSucceededAction response) { print('Auth code ${response.codeResponse.code}'); print('State: ${response.codeResponse.state}'); }, onError: (AuthorizationFailedAction e) { print('Error: ${e.toString()}'); }, ), |
In the case of the logout user(to the clear session from web view) then we are sending the ‘true’ value for destroySession
in LinkedInUserWidget
or LinkedInAuthCodeWidget
and also destroy the data from a local database.
You can create a LinkedIn user widget and use these properties to display that user information.
1 2 3 4 5 6 7 8 |
String firstName; String lastName; String accessToken; int expiresIn; String profilePicture; String email; String userId; (from version 0.1.) |
In this preview, you will see LinkedIn login and logout buttons. these widgets are default widgets provided by the LinkedIn library.
We learned how to use the LinkedIn sign-in our app and get user information for use in an application.
Visit the link for additional information on the LinkedIn login in the Flutter application
Thanks for reading this blog. You can also check other blogs from here for more knowledge.
Always be ready for learning 🙂
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.