branch feature/1_socialauth created (now 6c2eaa6f)
This is an automated email from the git hooks/post-receive script. New change to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git at 6c2eaa6f refs #1 utilisation de la lib socialauth pour se connecter via des services tiers This branch includes the following new commits: new 36f48513 refs #1 ajout des credentials sur le user new 6c2eaa6f refs #1 utilisation de la lib socialauth pour se connecter via des services tiers The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 6c2eaa6f74f9fed2166cc8067fd884213e38bf2a Author: Kevin Morin <morin@codelutin.com> Date: Fri Aug 11 17:52:32 2017 +0200 refs #1 utilisation de la lib socialauth pour se connecter via des services tiers commit 36f48513ff7b7fee5253db5daf5234de5103bd90 Author: Kevin Morin <morin@codelutin.com> Date: Fri Aug 11 17:52:10 2017 +0200 refs #1 ajout des credentials sur le user -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 36f48513ff7b7fee5253db5daf5234de5103bd90 Author: Kevin Morin <morin@codelutin.com> Date: Fri Aug 11 17:52:10 2017 +0200 refs #1 ajout des credentials sur le user --- .../persistence/entity/PollenUserTopiaDao.java | 22 +++++++++++++++++++-- .../db/migration/h2/V3_0_0_8__add_credentials.sql | 13 ++++++++++++ .../postgresql/V3_0_0_8__add_credentials.sql | 12 +++++++++++ pollen-persistence/src/main/xmi/pollen.properties | 2 +- pollen-persistence/src/main/xmi/pollen.zargo | Bin 26949 -> 27595 bytes 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java index a71e1cc1..06f84e33 100644 --- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java @@ -21,14 +21,16 @@ package org.chorem.pollen.persistence.entity; * #L% */ -import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.DaoUtils; import org.nuiton.util.pagination.PaginationParameter; import org.nuiton.util.pagination.PaginationResult; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; /** * @author Tony Chemit - dev@tchemit.fr @@ -42,7 +44,7 @@ public class PollenUserTopiaDao extends AbstractPollenUserTopiaDao<PollenUser> { public PaginationResult<PollenUser> findAll(PaginationParameter page, String search) { - Map<String, Object> parameters = Maps.newHashMap(); + Map<String, Object> parameters = new HashMap<>(); String hql = "SELECT user FROM " + PollenUser.class.getName() + " as user"; if (StringUtils.isNotBlank(search)) { @@ -68,4 +70,20 @@ public class PollenUserTopiaDao extends AbstractPollenUserTopiaDao<PollenUser> { super.delete(entity); } + + public Optional<PollenUser> tryFindUserWithCredential(String providerId, String userId) { + Objects.requireNonNull(providerId); + Objects.requireNonNull(userId); + + Map<String, Object> parameters = new HashMap<>(); + + String hql = "SELECT user FROM " + PollenUser.class.getName() + " as user " + + "INNER JOIN user." + PollenUser.PROPERTY_USER_CREDENTIAL + " as credentials " + + "WHERE credentials." + UserCredential.PROPERTY_PROVIDER + " = :providerId " + + "AND credentials." + UserCredential.PROPERTY_USER_ID + " = :userId"; + parameters.put("providerId", providerId); + parameters.put("userId", userId); + + return Optional.ofNullable(findUniqueOrNull(hql, parameters)); + } } diff --git a/pollen-persistence/src/main/resources/db/migration/h2/V3_0_0_8__add_credentials.sql b/pollen-persistence/src/main/resources/db/migration/h2/V3_0_0_8__add_credentials.sql new file mode 100644 index 00000000..1825b8ae --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/h2/V3_0_0_8__add_credentials.sql @@ -0,0 +1,13 @@ +-- credentials + +CREATE TABLE USERCREDENTIAL ( + TOPIAID VARCHAR(255) NOT NULL PRIMARY KEY, + TOPIAVERSION BIGINT NOT NULL, + TOPIACREATEDATE TIMESTAMP, + PROVIDER VARCHAR(255), + USERID VARCHAR(255), + EMAIL VARCHAR(255), + POLLENUSER VARCHAR(255), + FOREIGN KEY (POLLENUSER) references POLLENUSER(TOPIAID) +); + diff --git a/pollen-persistence/src/main/resources/db/migration/postgresql/V3_0_0_8__add_credentials.sql b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_0_0_8__add_credentials.sql new file mode 100644 index 00000000..2280308e --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_0_0_8__add_credentials.sql @@ -0,0 +1,12 @@ +-- credentials + +CREATE TABLE USERCREDENTIAL ( + TOPIAID VARCHAR(255) NOT NULL PRIMARY KEY, + TOPIAVERSION BIGINT NOT NULL, + TOPIACREATEDATE TIMESTAMP, + PROVIDER VARCHAR(255), + USERID VARCHAR(255), + EMAIL VARCHAR(255), + POLLENUSER VARCHAR(255), + FOREIGN KEY (POLLENUSER) references POLLENUSER(TOPIAID) +); diff --git a/pollen-persistence/src/main/xmi/pollen.properties b/pollen-persistence/src/main/xmi/pollen.properties index 49cb0e8f..16d95ab4 100644 --- a/pollen-persistence/src/main/xmi/pollen.properties +++ b/pollen-persistence/src/main/xmi/pollen.properties @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # #L% ###m -model.tagvalue.version=3.0.0.7 +model.tagvalue.version=3.0.0.8 #model.tagValue.notGenerateToString=true #model.tagValue.constantPrefix=PROPERTY_ #model.tagValue.useEnumerationName=true diff --git a/pollen-persistence/src/main/xmi/pollen.zargo b/pollen-persistence/src/main/xmi/pollen.zargo index f967fa89..72886764 100644 Binary files a/pollen-persistence/src/main/xmi/pollen.zargo and b/pollen-persistence/src/main/xmi/pollen.zargo differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 6c2eaa6f74f9fed2166cc8067fd884213e38bf2a Author: Kevin Morin <morin@codelutin.com> Date: Fri Aug 11 17:52:32 2017 +0200 refs #1 utilisation de la lib socialauth pour se connecter via des services tiers --- .../rest/api/PollenRestApiRequestFilter.java | 2 + .../org/chorem/pollen/rest/api/v1/AuthApi.java | 118 ++++++++++++++------- pollen-services/pom.xml | 5 + .../services/service/PollenServiceSupport.java | 5 + .../pollen/services/service/SocialAuthService.java | 101 ++++++++++++++++++ .../services/service/security/SecurityService.java | 6 +- .../src/main/resources/oauth_consumer.properties | 87 +++++++++++++++ pollen-ui-riot-js/package.json | 2 +- pollen-ui-riot-js/src/main/web/js/AuthService.js | 7 ++ pollen-ui-riot-js/src/main/web/js/Session.js | 49 +++++---- pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html | 14 ++- pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html | 16 ++- pollen-ui-riot-js/webpack.config.js | 2 +- pom.xml | 6 ++ 14 files changed, 356 insertions(+), 64 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java index 5ee83aa9..88370812 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java @@ -43,6 +43,7 @@ import org.chorem.pollen.services.service.PollenResourceService; import org.chorem.pollen.services.service.PollenUIUrlRenderService; import org.chorem.pollen.services.service.PollenUserService; import org.chorem.pollen.services.service.ReportService; +import org.chorem.pollen.services.service.SocialAuthService; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.services.service.VoteCountingTypeService; import org.chorem.pollen.services.service.VoteService; @@ -176,6 +177,7 @@ public class PollenRestApiRequestFilter implements ContainerRequestFilter, Conta ResteasyProviderFactory.pushContext(VoteService.class, serviceContext.newService(VoteService.class)); ResteasyProviderFactory.pushContext(PollenUserService.class, serviceContext.newService(PollenUserService.class)); ResteasyProviderFactory.pushContext(FeedbackService.class, serviceContext.newService(FeedbackService.class)); + ResteasyProviderFactory.pushContext(SocialAuthService.class, serviceContext.newService(SocialAuthService.class)); } private PollenUIContext extractUIContext(ContainerRequestContext context) { diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java index ffcc4507..55541664 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java @@ -21,6 +21,7 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import com.google.gson.Gson; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,6 +31,7 @@ import org.chorem.pollen.persistence.entity.SessionToken; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.service.PollenUserService; +import org.chorem.pollen.services.service.SocialAuthService; import org.chorem.pollen.services.service.security.MissingAuthenticationException; import org.chorem.pollen.services.service.security.PollenAuthenticationException; import org.chorem.pollen.services.service.security.PollenCypherTechnicalException; @@ -52,6 +54,8 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.NewCookie; import javax.ws.rs.core.Response; +import java.net.URI; +import java.util.Map; /** * TODO @@ -118,49 +122,58 @@ public class AuthApi { } PollenEntityRef<PollenUser> userPollenEntityRef = securityService.login(login, password, false); - userPollenEntityRef.encode(serviceContext.getTopiaApplicationContext().getTopiaIdFactory()); - - // Inject the session token in security context - SessionToken sessionToken = securityService.getSessionTokenByToken(userPollenEntityRef.getPermission()); - - securityContext.setSessionToken(sessionToken); - - // add auth cookies - - String value = securityService.encrypt( - sessionToken.getPollenUser().getTopiaId(), - sessionToken.getPollenToken().getToken() - ); - - NewCookie authCookie = new NewCookie( - COOKIE_POLLEN_AUTH, - value, - "/", - null, - null, - COOKIE_MAX_AGE, - false); - - NewCookie connectedCookie = new NewCookie( - COOKIE_POLLEN_CONNECTED, - "true", - "/", - null, - null, - COOKIE_MAX_AGE, - false); - - if (log.isDebugEnabled()) { - log.debug("Add auth cookie:: " + authCookie.getValue()); - } - - return Response.ok(userPollenEntityRef).cookie(authCookie, connectedCookie).build(); + return getLoginResponseFromPollenUser(serviceContext, securityService, securityContext, userPollenEntityRef); } throw new MissingAuthenticationException(); } + protected Response getLoginResponseFromPollenUser(PollenServiceContext serviceContext, + SecurityService securityService, + PollenSecurityContext securityContext, + PollenEntityRef<PollenUser> userPollenEntityRef) + throws PollenInvalidSessionTokenException, PollenCypherTechnicalException { + + userPollenEntityRef.encode(serviceContext.getTopiaApplicationContext().getTopiaIdFactory()); + + // Inject the session token in security context + SessionToken sessionToken = securityService.getSessionTokenByToken(userPollenEntityRef.getPermission()); + + securityContext.setSessionToken(sessionToken); + + // add auth cookies + + String value = securityService.encrypt( + sessionToken.getPollenUser().getTopiaId(), + sessionToken.getPollenToken().getToken() + ); + + NewCookie authCookie = new NewCookie( + COOKIE_POLLEN_AUTH, + value, + "/", + null, + null, + COOKIE_MAX_AGE, + false); + + NewCookie connectedCookie = new NewCookie( + COOKIE_POLLEN_CONNECTED, + "true", + "/", + null, + null, + COOKIE_MAX_AGE, + false); + + if (log.isDebugEnabled()) { + log.debug("Add auth cookie:: " + authCookie.getValue()); + } + + return Response.ok(userPollenEntityRef).cookie(authCookie, connectedCookie).build(); + } + @Path("/login2") @POST @PUT public PollenEntityRef<PollenUser> login2(@Context SecurityService securityService, @@ -172,8 +185,39 @@ public class AuthApi { PollenUserBannedException { return securityService.login(login, password, rememberMe); + } + @Path("/login/{providerId}") + @GET + public Response loginProvider(@Context SocialAuthService socialAuthService, + @PathParam("providerId") String providerId, + @QueryParam("providerRedirection") String providerRedirection) + throws Exception { + + String providerLoginUrl = socialAuthService.getProviderAuthenticationUrl(providerId, providerRedirection); + return Response.seeOther(URI.create(providerLoginUrl)).build(); } + + @Path("/login/{providerId}") + @POST + public Response loginProvider(@Context SocialAuthService socialAuthService, + @Context PollenServiceContext serviceContext, + @Context SecurityService securityService, + @Context PollenSecurityContext securityContext, + @PathParam("providerId") String providerId, + String providerRedirection, + @HeaderParam("authorization") String authorization) + throws Exception { + + Gson gson = new Gson(); + Map<String, String> paramsMap = gson.fromJson(authorization, Map.class); + PollenEntityRef<PollenUser> userPollenEntityRef = socialAuthService.login(providerId, providerRedirection, paramsMap); + + + + return getLoginResponseFromPollenUser(serviceContext, securityService, securityContext, userPollenEntityRef); + } + @Path("/logout") @GET public boolean logout(@Context SecurityService securityService, diff --git a/pollen-services/pom.xml b/pollen-services/pom.xml index a17b864f..43ed09cb 100644 --- a/pollen-services/pom.xml +++ b/pollen-services/pom.xml @@ -214,6 +214,11 @@ <artifactId>jboss-jaxrs-api_2.0_spec</artifactId> </dependency> + <dependency> + <groupId>org.brickred</groupId> + <artifactId>socialauth</artifactId> + </dependency> + </dependencies> <build> diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java index 88b0a6ca..c26c5f50 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java @@ -41,6 +41,7 @@ import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; import org.chorem.pollen.persistence.entity.ReportTopiaDao; import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao; +import org.chorem.pollen.persistence.entity.UserCredentialTopiaDao; import org.chorem.pollen.persistence.entity.VoteToChoiceTopiaDao; import org.chorem.pollen.persistence.entity.VoteTopiaDao; import org.chorem.pollen.persistence.entity.VoterListMemberTopiaDao; @@ -213,6 +214,10 @@ public abstract class PollenServiceSupport implements PollenService { return getPersistenceContext().getPollenUserDao(); } + protected UserCredentialTopiaDao getUserCredentialDao() { + return getPersistenceContext().getUserCredentialDao(); + } + protected ReportTopiaDao getReportTopiaDao() { return getPersistenceContext().getReportDao(); } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java new file mode 100644 index 00000000..47cb08dd --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java @@ -0,0 +1,101 @@ +package org.chorem.pollen.services.service; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.brickred.socialauth.AuthProvider; +import org.brickred.socialauth.Profile; +import org.brickred.socialauth.SocialAuthConfig; +import org.brickred.socialauth.SocialAuthManager; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.PollenUserImpl; +import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; +import org.chorem.pollen.persistence.entity.UserCredential; +import org.chorem.pollen.persistence.entity.UserCredentialImpl; +import org.chorem.pollen.services.bean.PollenEntityRef; + +import java.util.Map; +import java.util.Optional; + +/** + * @author Kevin Morin (Code Lutin) + */ +public class SocialAuthService extends PollenServiceSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SocialAuthService.class); + + public String getProviderAuthenticationUrl(String providerId, String redirection) throws Exception { + SocialAuthManager manager = getSocialAuthManager(); + + // get Provider URL to which you should redirect for authentication. + // id can have values "facebook", "twitter", "yahoo" etc. or the OpenID URL + return manager.getAuthenticationUrl(providerId, redirection); + } + + public PollenEntityRef<PollenUser> login(String providerId, + String redirection, + Map<String, String> paramsMap) throws Exception { + SocialAuthManager manager = getSocialAuthManager(); + manager.getAuthenticationUrl(providerId, redirection); + + AuthProvider provider = manager.connect(paramsMap); + + // get profile + Profile p = provider.getUserProfile(); + + PollenUser pollenUser; + PollenUserTopiaDao userDao = getPollenUserDao(); + Optional<PollenUser> pollenUserForCredential = userDao.tryFindUserWithCredential(p.getProviderId(), p.getValidatedId()); + + String name = p.getDisplayName(); + if (name == null) { + name = p.getFirstName() + " " + p.getLastName(); + } + + if (pollenUserForCredential.isPresent()) { + if (log.isInfoEnabled()) { + log.info("credentials found : " + name); + } + pollenUser = pollenUserForCredential.get(); + + } else { + if (log.isInfoEnabled()) { + log.info("create new user : " + name); + } + + UserCredential credential = new UserCredentialImpl(); + credential.setProvider(p.getProviderId()); + credential.setUserId(p.getValidatedId()); + credential.setEmail(p.getEmail()); + credential = getUserCredentialDao().create(credential); + + pollenUser = new PollenUserImpl(); + pollenUser.setName(name); + pollenUser.setEmail(p.getEmail()); + pollenUser.setLanguage(p.getLanguage()); + pollenUser.setAdministrator(false); + pollenUser.setBanned(false); + pollenUser.addUserCredential(credential); + pollenUser = userDao.create(pollenUser); + + commit(); + } + + return getSecurityService().getSessionTokenForUser(pollenUser); + } + + protected SocialAuthManager getSocialAuthManager() throws Exception { + //Create an instance of SocialAuthConfgi object + SocialAuthConfig config = SocialAuthConfig.getDefault(); + + //load configuration. By default load the configuration from oauth_consumer.properties. + //You can also pass input stream, properties object or properties file name. + config.load(); + + //Create an instance of SocialAuthManager and set config + SocialAuthManager manager = new SocialAuthManager(); + manager.setSocialAuthConfig(config); + + return manager; + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java index 6eaebb94..1ccb28bb 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java @@ -138,6 +138,11 @@ public class SecurityService extends PollenServiceSupport { } PollenUser user = getPollenUserDao().forEmailEquals(login).findUnique(); + return getSessionTokenForUser(user); + + } + + public PollenEntityRef<PollenUser> getSessionTokenForUser(PollenUser user) throws PollenEmailNotValidatedException, PollenUserBannedException { if (!user.isEmailValidated()) { throw new PollenEmailNotValidatedException(); } @@ -163,7 +168,6 @@ public class SecurityService extends PollenServiceSupport { commit(); return PollenEntityRef.of(sessionToken); - } public void logout() { diff --git a/pollen-services/src/main/resources/oauth_consumer.properties b/pollen-services/src/main/resources/oauth_consumer.properties new file mode 100644 index 00000000..6f015cc3 --- /dev/null +++ b/pollen-services/src/main/resources/oauth_consumer.properties @@ -0,0 +1,87 @@ +#google +www.google.com.consumer_key = opensource.brickred.com +www.google.com.consumer_secret = YC06FqhmCLWvtBg/O4W/aJfj + +#you can set custom permission by using custom_permissions with provider prefix. +#www.google.com.custom_permissions = http://www.google.com/m8/feeds/,http://picasaweb.google.com/data/ + +#you can set OAuth endpoint (RequestToken URL, Authorization URL and AccessToken URL) if required or need +#to pass extra parameter +#www.google.com.request_token_url +#www.google.com.authentication_url +#www.google.com.access_token_url + +#New registration on google will always provide OAuth2 keys which is supported by GooglePlus provider +#google plus +googleapis.com.consumer_key = XXXXXXX +googleapis.com.consumer_secret = XXXXXXXX + + +#yahoo +api.login.yahoo.com.consumer_key = dj0yJmk9VTdaSUVTU3RrWlRzJmQ9WVdrOWNtSjZNMFpITm1VbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iMA-- +api.login.yahoo.com.consumer_secret = 1db3d0b897dac60e151aa9e2499fcb2a6b474546 + +#twitter +twitter.com.consumer_key = E3hm7J9IQbWLijpiQG7W8Q +twitter.com.consumer_secret = SGKNuXyybt0iDdgsuzVbFHOaemV7V6pr0wKwbaT2MH0 + +#facebook +graph.facebook.com.consumer_key = 152190004803645 +graph.facebook.com.consumer_secret = 64c94bd02180b0ade85889b44b2ba7c4 +#you can set custom permission by using custom_permissions with provider prefix. +#graph.facebook.com.custom_permissions = publish_stream,email,user_birthday,user_location,offline_access + +#hotmail +consent.live.com.consumer_key = 000000004403D60E +consent.live.com.consumer_secret = cYqlii67pTvgPD4pdB7NUVC7L4MIHCcs + +#Same keys will work for Linkedin OAuth2 provider +#LinkedIn +api.linkedin.com.consumer_key = 9-mmqg28fpMocVuAg87exH-RXKs70yms52GSFIqkZN25S3m96kdPGBbuSxdSBIyL +api.linkedin.com.consumer_secret = e6NBqhDYE1fX17RwYGW5vMp25Cvh7Sbw9t-zMYTIW_T5LytY5OwJ12snh_YftgE4 + +#MySpace +api.myspace.com.consumer_key = 29db395f5ee8426bb90b1db65c91c956 +api.myspace.com.consumer_secret = 0fdccc829c474e42867e16b68cda37a4c4b7b08eda574fe6a959943e3e9be709 + +#FourSquare +foursquare.com.consumer_key = JQKEM1PHWFW4YF2YPEQBRRESXE3SBGNCYJWWDTZKF3IZNJ3V +foursquare.com.consumer_secret = 4IILLDFDVPP2LC554S4KXKETQNTDKPDSEVCKVHA2QEHKYBEQ + +#Yammer +www.yammer.com.consumer_key=5zyIkp12TrkulSRbSegQ +www.yammer.com.consumer_secret=zUcCB9kqWhI1IiTAJbl9QdG2AWcUJMDWp3Qyv5VJJw + +#Please use your own keys for mendeley +#Mendeley +#api.mendeley.com.consumer_key= +#api.mendeley.com.consumer_secret= + +#Salesforce +login.salesforce.com.consumer_key = 3MVG9Y6d_Btp4xp4yFMR0tPSndkAVu4OBejuYcL2iGFC68tA49PknWKX20XdPl5s1iwWldyuAbSINWHbB2Jcu +login.salesforce.com.consumer_secret = 1993703471433041656 + +#Instagram +api.instagram.com.consumer_key=f1e23002a9da49f696d439368624c9fc +api.instagram.com.consumer_secret=f274614621f64d498cb3458b3736827a + +#Flickr +www.flickr.com.consumer_key=942a1a394b866a30dc9b4ad8db5cb8f8 +www.flickr.com.consumer_secret=f90c5bee8a8de964 + +#GITHub +api.github.com.consumer_key=4ffc69764a59dd3ce347 +api.github.com.consumer_secret=dc62937c1d7bb9ce30cb654a26d4a575858f5e1f + +#Implementations +#you can provide your custom provider here e.g 'myprovider' is your provider id +#and 'org.brickred.socialauth.provider.GoogleImpl' is your provider implementation. +#provider id should be prefixed here with 'socialauth.' +#socialauth.myprovider = org.brickred.socialauth.provider.GoogleImpl + +#If you want to set proxy for internal http calls, so you can set in following way +#proxy.host=YOUR HOST NAME(e.g. 127.0.0.1) +#proxy.port=PORT(e.g.8888) + +#If you want to set connection timeout, you can set in following way +#http.connectionTimeOut = TIMEOUT(e.g. 5000) \ No newline at end of file diff --git a/pollen-ui-riot-js/package.json b/pollen-ui-riot-js/package.json index 68ec61e0..d542116f 100644 --- a/pollen-ui-riot-js/package.json +++ b/pollen-ui-riot-js/package.json @@ -24,7 +24,7 @@ } ], "scripts": { - "start": "webpack-dev-server --hot --inline --host 0.0.0.0 --public localhost:8080", + "start": "webpack-dev-server --hot --inline --host 0.0.0.0 --public opensource.brickred.com:8080", "package": "webpack --bail" }, "devDependencies": { diff --git a/pollen-ui-riot-js/src/main/web/js/AuthService.js b/pollen-ui-riot-js/src/main/web/js/AuthService.js index 54f272c4..23b87d3a 100644 --- a/pollen-ui-riot-js/src/main/web/js/AuthService.js +++ b/pollen-ui-riot-js/src/main/web/js/AuthService.js @@ -68,6 +68,13 @@ class AuthService extends FetchService { return this.post("/v1/resendValidation", email); } + signInProvider(provider, query, providerRedirection) { + return this.fetch( + "/v1/login/" + provider, + "POST", + {Authorization: JSON.stringify(query)}, + providerRedirection); + } } module.exports = singleton(AuthService); diff --git a/pollen-ui-riot-js/src/main/web/js/Session.js b/pollen-ui-riot-js/src/main/web/js/Session.js index bd294085..d1af7ac7 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -130,26 +130,33 @@ class Session { } signIn(login, password) { - return authService.signIn(login, password).then(auth => { - logger.info("SignIn::"); - logger.info(auth); - return authService.userPromise(auth).then((user) => { - if (!user) { - logger.info("SignIn error"); - var oldUser = this.user; - this.user = null; - bus.trigger("user", this.user, oldUser); - return Promise.reject(); - } - logger.info("SignIn user::"); - logger.info(user); - pageTracker.trackLogin(); - var oldUser = this.user; - this.user = user; - bus.trigger("user", this.user, oldUser); + return authService.signIn(login, password).then(auth => this.updateConnection(auth, this)); + } - return this.user; - }); + signInProvider(provider, query) { + return authService.signInProvider(provider, query, this.getProviderRedirectionUrl(query.redirect)) + .then(auth => this.updateConnection(auth, this)); + } + + updateConnection(auth, session) { + logger.info("SignIn::"); + logger.info(auth); + return authService.userPromise(auth).then((user) => { + if (!user) { + logger.info("SignIn error"); + var oldUser = session.user; + session.user = null; + bus.trigger("user", session.user, oldUser); + return Promise.reject(); + } + logger.info("SignIn user::"); + logger.info(user); + pageTracker.trackLogin(); + var oldUser = session.user; + session.user = user; + bus.trigger("user", session.user, oldUser); + + return session.user; }); } @@ -162,6 +169,10 @@ class Session { }); } + getProviderRedirectionUrl(redirect) { + return this.pollenUIContext.uiEndPoint + "/?redirect=" + redirect; + } + } module.exports = singleton(Session); diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html index 8825148a..1ac4f6cb 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html @@ -218,8 +218,18 @@ require("./popup/InformationPopup.tag.html"); }); route(() => { - this.bus.trigger("pageChanged", "home"); - riot.mount(this.refs.content, "home"); + var q = route.query(); + console.log(q); + console.log(q.redirect); + if (q.redirect != null) { + session.signInProvider("facebook", q).then(() => { + location.href = session.pollenUIContext.uiEndPoint + "/" + unescape(decodeURIComponent(q.redirect)); + }); + + } else { + this.bus.trigger("pageChanged", "home"); + riot.mount(this.refs.content, "home"); + } }); window.onkeydown = e => { diff --git a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html index e6fb6efb..739345e8 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html @@ -57,6 +57,10 @@ require("./components/HumanInput.tag.html"); </div> <a onclick="{newPassword}">{__.lostpassword}</a> </form> + <p>Ou connectez vous avec votre compte + <a onclick="{signinWithProvider('facebook')}"><i class="fa fa-facebook-official"></i></a> + <a onclick="{signinWithProvider('linkedin')}"><i class="fa fa-linkedin-square"></i></a> + </p> </div> <SignUp/> @@ -68,10 +72,10 @@ require("./components/HumanInput.tag.html"); </div> <script type="es6"> - let session = require("../js/Session"); + this.session = require("../js/Session"); let route = require("riot-route"); - this.installBundle(session, "signin"); + this.installBundle(this.session, "signin"); this.message = ""; this.openSignIn = false; @@ -95,7 +99,7 @@ require("./components/HumanInput.tag.html"); this.message = ""; - session.signIn(this.refs.login.value, this.refs.password.value) + this.session.signIn(this.refs.login.value, this.refs.password.value) .then(() => { this.openSignIn = false; this.update(); @@ -106,6 +110,12 @@ require("./components/HumanInput.tag.html"); }); }); }; + + this.signinWithProvider = (provider) => (e) => { + let redirect = location.hash || "#"; + location.href = this.session.configuration.endPoint + "/v1/login/" + provider + + "?providerRedirection=" + this.session.getProviderRedirectionUrl(escape(encodeURIComponent(redirect))); + }; </script> <style> diff --git a/pollen-ui-riot-js/webpack.config.js b/pollen-ui-riot-js/webpack.config.js index 0a233ab7..11ae81fb 100644 --- a/pollen-ui-riot-js/webpack.config.js +++ b/pollen-ui-riot-js/webpack.config.js @@ -34,7 +34,7 @@ module.exports = { new CopyWebpackPlugin([ {from: "src/main/web/conf.js", transform: function(content) { - return content.toString().replace("POLLEN_API_URL", JSON.stringify(process.env.POLLEN_SERVER_CONTEXT || "http://localhost:8888/pollen-rest-api")); + return content.toString().replace("POLLEN_API_URL", JSON.stringify(process.env.POLLEN_SERVER_CONTEXT || "http://opensource.brickred.com:8888/pollen-rest-api")); }}, {from: "src/main/web/index.html"}, {from: "src/main/web/home", to: "home"}, diff --git a/pom.xml b/pom.xml index bcc9711a..d92084cf 100644 --- a/pom.xml +++ b/pom.xml @@ -627,6 +627,12 @@ </exclusions> </dependency> + <dependency> + <groupId>org.brickred</groupId> + <artifactId>socialauth</artifactId> + <version>4.14</version> + </dependency> + <!--dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm