Here we will show how to quickly integrate Sequencing OAuth2 harnesses into your JEE based environment.
There are several prerequisites in order to complete the integration:
- you need to have a Sequencing account
- you need to have an OAuth2 application secret
- you need to have at one of IDEs - Eclipse, IntelliJ Idea or Netbeans
We have also deployed this code so you can test it in action here.
Sequencing.com provides 2 possibilities to integrate OAuth2 for JEE environments
- Pure servlet based
- Spring boot based
Servlet based environment integration
1) Visit https://github.com/SequencingDOTcom/OAuth2-code-with-demo repository
2) Clone repository locally to your environment
$ git clone https://github.com/SequencingDOTcom/OAuth2-code-with-demo.git
3) Servlet based Maven project is in "java-servlet" folder
4) Review pom.xml and integrate dependencies into your project
5) Review web.xml and integrate servlet definitions into your project
6) Copy classes from com.sequencing.oauth2demo.servlet to your project
7) Edit configuration settings in SequencingServletContextListener class so to make them conform your OAuth2 application settings. Make sure that application name, secret and redirect URL matches.
OAuth2 management interface is available in the developer center under "Manage OAuth2 secrets" section.
SequencingServletContextListener snippet from the repository | SequencingServletContextListener snippet with actual OAuth data |
---|---|
public AuthenticationParameters getAppConfig() { return new AuthenticationParameters.ConfigurationBuilder() .withRedirectUri("https://java-oauth-demo.sequencing.com/Default/Authcallback") .withClientId("oAuth2 Demo Java") .withClientSecret("vuwpK04r7ylcbe1oUJCrDXza7dj33ejcUkBY06jrmzYiYw8LEmd1IkUZnKBCmv-fiuIhQkCm_qNWoQ81eCsY7A") .build(); } |
public AuthenticationParameters getAppConfig() { return new AuthenticationParameters.ConfigurationBuilder() .withRedirectUri("http://feedme.com/Default/AuthCallback") .withClientId("feedme") .withClientSecret("RCGK_tcZliZw2z5BqCSr_r-psBTTGBqji_WWEyjNZnp8-eQ1hgle5d1IS_of_U7wkshNvCqXBs25B6Q7JL1EBA") .build(); } |
After authorization is completed tokens can be accessed by following call. We recommend keeping them safe.
SequencingOAuth2Client oauthClient = (SequencingOAuth2Client) config.getServletContext().getAttribute(SequencingServletContextListener.CFG_OAUTH_HANDLER);
oauthClient.getToken();
Spring boot based environment integration
1) Visit https://github.com/SequencingDOTcom/OAuth2-code-with-demo repository
2) Clone repository locally to your environment
$ git clone https://github.com/SequencingDOTcom/OAuth2-code-with-demo.git
3) Servlet based Maven project is in "java-spring" folder
4) Review pom.xml and integrate dependencies into your project
6) Copy classes from com.sequencing.oauth2demo to your project
7) Edit configuration settings in application.properties file so to make them conform your OAuth2 application settings. Make sure that application name, secret and redirect URL matches.
OAuth2 management interface is available in the developer center under "Manage OAuth2 secrets" section.
application.properties snippet from the repository | application.properties snippet with actual OAuth2 tokens |
---|---|
redirectUri=https://java-oauth-demo.sequencing.com/Default/Authcallback clientId=oAuth2 Demo Java clientSecret=vuwpK04r7ylcbe1oUJCrDXza7dj33ejcUkBY06jrmzYiYw8LEmd1IkUZnKBCmv- fiuIhQkCm_qNWoQ81eCsY7A |
redirectUri=http://feedme.com/Default/AuthCallback clientId=feedme clientSecret=RCGK_tcZliZw2z5BqCSr_r-psBTTGBqji_WWEyjNZnp8- eQ1hgle5d1IS_of_U7wkshNvCqXBs25B6Q7JL1EBA |
After authorization is completed tokens can be accessed by following call. We recommend keeping them safe.
// inject dependency first
@Autowired
private SequencingOAuth2Client oauth;
// access token in this way
oauth.getToken();
Testing result
1) Deploy and start application
2) Point your browse to http://feedme.com/Default/AuthCallback
It will trigger redirect to Sequencing authorization page
After entering credentials you will be presented with access approval which contains application details
After clicking on "Yes (I authorize access)" result page will render (result.php) that contains list of sample files available in your account