Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linkedin login #285

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions community_app_boilerplate/lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:communityappboilerplate/services/user.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:github_sign_in/github_sign_in.dart'; //TODO
import 'package:linkedin_login/linkedin_login.dart';

//TODO: import '../secret.dart';
import '../secret.dart';

final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn();
Expand Down Expand Up @@ -35,7 +37,8 @@ class AuthService {

Future registerWithEmailAndPassword(String name, String email, String password) async {
try {
AuthResult result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
AuthResult result =
await _auth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = result.user;
if (user != null) {
_firestore.collection('/users').document(user.uid).setData({
Expand Down Expand Up @@ -155,4 +158,58 @@ class AuthService {
_userFromFirebaseUser(user.user);
return user;
}*/

Widget signInWithLinkedIn(BuildContext context) {
return LinkedInUserWidget(
appBar: AppBar(
title: Text('GirlScript'),
),
destroySession: false,
redirectUrl: REDIRECT_URL_LINKEDIN,
clientId: CLIENT_ID_LINKEDIN,
clientSecret: CLIENT_SECRET_LINKEDIN,
projection: [
ProjectionParameters.id,
ProjectionParameters.localizedFirstName,
ProjectionParameters.localizedLastName,
ProjectionParameters.firstName,
ProjectionParameters.lastName,
ProjectionParameters.profilePicture,
],
onGetUserProfile: (LinkedInUserModel linkedInUser) {
final user = linkedInLoginFireBase(linkedInUser.token.accessToken);
if (user != null) Navigator.pop(context);
},
catchError: (LinkedInErrorObject error) {
print('Error description: ${error.description},'
' Error code: ${error.statusCode.toString()}');
Navigator.pop(context);
},
);
}

linkedInLoginFireBase(String token) async {
final user = await _auth.signInWithCustomToken(token: token);

name = user.user.displayName;
email = user.user.email;
imageUrl = user.user.photoUrl;

if (user != null) {
await _firestore.collection('/users').document(user.user.uid).setData({
'name': name,
'email': email,
'profileImageUrl': imageUrl,
});
}

assert(!user.user.isAnonymous);
assert(await user.user.getIdToken() != null);

final FirebaseUser currentUser = await _auth.currentUser();
assert(user.user.uid == currentUser.uid);

_userFromFirebaseUser(user.user);
return user;
}
}
31 changes: 24 additions & 7 deletions community_app_boilerplate/lib/ui/screens/auth/signUpScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class _SignUpScreenState extends State<SignUpScreen> {
final AuthService _auth = AuthService();

String emailValidator(String value) {
Pattern pattern = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
Pattern pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regex = new RegExp(pattern);
if (value.isEmpty) return '*Required';
if (!regex.hasMatch(value))
Expand Down Expand Up @@ -232,7 +233,10 @@ class _SignUpScreenState extends State<SignUpScreen> {
});
},
validator: (value) => value.isEmpty ? '*Required' : null,
decoration: inputTextDecoration.copyWith(labelText: "Username", icon: Icon(Icons.person_outline, color: Colors.black87, size: 30)),
decoration: inputTextDecoration.copyWith(
labelText: "Username",
icon: Icon(Icons.person_outline,
color: Colors.black87, size: 30)),
),
),
SizedBox(height: height * 0.015),
Expand All @@ -248,7 +252,10 @@ class _SignUpScreenState extends State<SignUpScreen> {
});
},
validator: (value) => value.isEmpty ? '*Required' : null,
decoration: inputTextDecoration.copyWith(labelText: "Password", icon: Icon(Icons.lock_outline, color: Colors.black87, size: 30)),
decoration: inputTextDecoration.copyWith(
labelText: "Password",
icon: Icon(Icons.lock_outline,
color: Colors.black87, size: 30)),
),
),
SizedBox(height: height * 0.015),
Expand All @@ -263,7 +270,10 @@ class _SignUpScreenState extends State<SignUpScreen> {
});
},
validator: emailValidator,
decoration: inputTextDecoration.copyWith(labelText: "Email", icon: Icon(Icons.mail_outline, color: Colors.black87, size: 30)),
decoration: inputTextDecoration.copyWith(
labelText: "Email",
icon: Icon(Icons.mail_outline,
color: Colors.black87, size: 30)),
),
),
SizedBox(height: height * 0.015),
Expand Down Expand Up @@ -308,7 +318,8 @@ class _SignUpScreenState extends State<SignUpScreen> {
setState(() {
_loading = true;
});
dynamic result = await _auth.registerWithEmailAndPassword(_userName, _email, _password);
dynamic result = await _auth.registerWithEmailAndPassword(
_userName, _email, _password);
print(result);
switch (result) {
case "ERROR_EMAIL_ALREADY_IN_USE":
Expand All @@ -322,7 +333,8 @@ class _SignUpScreenState extends State<SignUpScreen> {
case "ERROR_WEAK_PASSWORD":
{
setState(() {
errorMsg = "The password must be 6 characters long or more.";
errorMsg =
"The password must be 6 characters long or more.";
_loading = false;
});
}
Expand Down Expand Up @@ -476,7 +488,12 @@ class _SignUpScreenState extends State<SignUpScreen> {
child: RaisedButton(
elevation: 6,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
onPressed: () {},
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => _auth.signInWithLinkedIn(context),
),
),
color: Color(0xff2867B2),
padding: EdgeInsets.all(9),
child: Row(
Expand Down
1 change: 1 addition & 0 deletions community_app_boilerplate/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
uni_links: ^0.4.0
http: ^0.12.2
github_sign_in: ^0.0.3
linkedin_login: ^1.2.2

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down