Spring Social, Create connection for existing local users on signin -
i trying allow existing local users signin using spring social, google, , automatically create new userconnection if email matches local account.
i have found examples implicit signup (requires/creates new account), new user signup (default action if springsocial fails find userconnection) , connect option while current user logged in.
how can extend springsocial let me check existing social user / local user email match, create user connection existing local user , sign them both local , social?
you can use implicit sign find account instead of creating new one.
modifying code found implicit sign up, can similar following:
public class accountconnectionsignup implements connectionsignup { private final accountrepository accountrepository; public accountconnectionsignup(accountrepository accountrepository) { this.accountrepository = accountrepository; } public string execute(connection<?> connection) { userprofile profile = connection.fetchuserprofile(); account account = accountrepository.findaccountbyemail(profile.getemail()); return account == null ? null : account.getusername(); } }
you need implement account
, accountrepository
support email property, use repository find account email. if repository cannot find account, return null.
Comments
Post a Comment