-
Notifications
You must be signed in to change notification settings - Fork 35
Quick Start
Log In with PayPal (formerly PayPal Access) is a commerce identity solution that enables your customers to sign in to your web site quickly and securely using their PayPal login credentials
More information on 'Login With PayPal' here.
Recently updated documentation on how to obtain appid can be found here. Please look under "Creating a Personal test account" section.
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>${org.springframework.social-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>${org.springframework.social-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social.openidconnect</groupId>
<artifactId>spring-social-paypal</artifactId>
<version>${org.springframework.social.paypal-version}</version>
</dependency>
Note that the examples above are using ${...}
Maven properties. Refer to the Quickstart Sample POM for a complete sample.
Spring Social configuration is done through a class SocialConfig
in your application, which defines what Spring Social extension will be used (PayPal in our case). In specific, you need to define the following:
- The application id and secret obtained in the step #1.
- A connection factory which defines how Spring Social should connect to the API:
PayPalConnectionFactory
. You can use PayPalConnectionFactoryBuilder to create the same. Builder also gives additional options. - PayPalConnectionFactoryBuilder allows you to override default endpoints. This is done to aid testing. If you want to swap endpoints to stage server or simulator then you can use this feature. You might have to disable strict verifier when you do this.
- Connections repository for all users and for the current user, so Spring Social can persist the connection data.
- Connection data can be persisted in a database table or in InMemory Map. OpenId Connect protocol has an extra attribute id_token which is not used in OAuth2 protocol. This token is used on checkid and disconnect endpoints. Hence a new [sql script] (https://github.com/paypal/spring-social-paypal-openidconnect/blob/master/src/main/resources/org/springframework/social/openidconnect/jdbc/OpenIdConnectJdbcConnectionRepository.sql) is provided as part of spring-social-paypal extension jar. If you intend to use JDBC connection repository, then you have to make sure this script is run before.
- spring-social-paypal extension jar also provides a InMemory connection repository implementation which is not provided by spring-social-core. You can switch to use JDBC or in-memory when you are configuring Connection repository.
- A bean representing the API calls: Interface
PayPal
Use the Quickstart Sample SocialConfig as a template for your own application. Also note that the sample SocialConfig reads the application id and secret id from a property file application.properties
- A
ProviderSignInController
(provided by Spring Social) is used to redirect the user to the PayPal site for authentication, passing the objects instantiated on step #3 above. If is defined inSocialConfig.java
along with other configurations. You can also optionally setpostSignInUrl
if you intend to invoke another action after successful signin. - Sign in and sign out views must also be provided. The Sign in process is started with a simple form that does a POST to
/signin/paypal
. Refer to [Quickstart Sample Sign In View] (https://github.com/paypal/spring-social-security-paypal-openidconnect-quickstart/blob/master/src/main/webapp/WEB-INF/views/signin.jsp)
PayPal Access supports both pop-up-based login and single-window login. To enable the pop-up, we create a window using Javascript when the user clicks on the submit form button, and then the form itself refreshes the pop-up via the target
HTML attribute. Then when home.jsp
is loading it closes itself and refreshes the parent window
Refer to Quickstart Sample Sign In View
Now the PayPal Access API (which is represented by the interface PayPal
) is ready to be used, and it can be easily injected into other controllers. See [Quickstart Sample Home Controller] (https://github.com/paypal/spring-social-security-paypal-openidconnect-quickstart/blob/master/src/main/java/org/springframework/social/quickstart/HomeController.java)
- Spring Social Quick Start: https://github.com/SpringSource/spring-social/wiki/Quick-Start
- PayPal Access Documentation: https://developer.paypal.com/webapps/developer/docs/classic/loginwithpaypal/gs_loginwithpaypal