linkedin_login
OpenID を使用した LinkedIn OAuth V2 サービスによるログイン用ライブラリ。このライブラリは、LinkedIn OAuth API との認証を実装するのに役立ちます。
Flutter用のLinkedIn OAuthログイン
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
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.
minSdkVersion for different setup:
-- If you are using Hybrid Composition (default from version 2.1.0) your minSdkVersion should be at least 19
-- If you want to use Virtual displays (default before version 2.1.0) your minSdkVersion should be at least 20To read more why this lib needs to use one of these two modes please visit docs of webview_flutter
Since LinkedIn introduce new way of signing in with LinkedIn called "Sign In with LinkedIn using OpenID Connect" and they are deprecating and removing "Sign In with LinkedIn" from product list (see LinkedIn console where you have created your app) this library needs to have few breaking changes duo change of architecture. Sorry for that in advance.
/me API is removed and from now on library is using /userinfo docsopenid, email, profile{
"sub": "xxxx",
"email_verified": true,
"name": "xxxx",
"locale": {
"country": "US",
"language": "en"
},
"given_name": "xxxx",
"family_name": "xxxx",
"email": "xxxx",
"picture": "xxxx"
}
For more details about this change you can navigate to this issue
You can see full example under this project.
Call LinkedIn authorization and get user object:
LinkedInUserWidget(
redirectUrl: redirectUrl,
clientId: clientId,
clientSecret: clientSecret,
onGetUserProfile:
(UserSucceededAction linkedInUser) {
print('Access token ${linkedInUser.user.token}');
print('First name: ${linkedInUser.user.givenName}');
print('Last name: ${linkedInUser.user.familyName}');
},
onError: (UserFailedAction e) {
print('Error: ${e.toString()}');
},
)
Or you can just fetch authorization code (clientSecret is not required in this widget):
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()}');
},
),
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.
String name;
String familyName;
String givenName;
bool isEmailVerified;
String sub;
String accessToken;
int expiresIn;
String picture;
String email;
LinkedInPreferredLocal locale; (from version 0.1.)
r_emailaddress and r_liteprofile scopes will be removed from LinkedIn after 30 of November and they are removed from library after 3.x.x version.
Now you should add under "Products" -> "Sign In With LinkedIn using OpenID Connect"
https://www.linkedin.com/developers/apps/{REPLACE_WITH_ID_OF_YOUR_APP}/products
OpenId is requiring openid scope with in combination of at least Email or Profile scope, but by default this library is adding three scopes
final scopes = const [
OpenIdScope(),
EmailScope(),
ProfileScope(),
],
You are also able to create custom scopes by extending Scope class
class CustomScope extends Scope {
const CustomScope() : super('whatever_scope_of_name_to_map_with_linkedin_api');
}
However please take in consideration limitations of this library under section known limitations
inside this file.
String code; // authorization code
String state;
Standard LinkedIn button for login. This widget is modifiable.
LinkedInButtonStandardWidget(onTap: () {});
flutter packages pub run build_runner build --delete-conflicting-outputs
w_member_social