User Authentication: Design and Development

Hi all,

We had suggestions to use the Linkedin developer APIs to provide Single-Sign-On functionality. Following is the summary of my research on the subject,

SpringBoot provides the dependency spring-boot-starter-social-linkedin to autoconfigure Linkedin. Using the dependency with spring-security we can provide users with authorizations access to the application. Below is a brief guide on how to implement the application,

A login API will be created. When a request is made to this API 2 outcomes can be expected,

  1. If the user has connected Linkedin profile: User will be logged in and a session will be created
  2. If not user will be redirected to connect their Linkedin account. After connecting userā€™s profile data will be persisted in the database.

Spring Social Provider is soo awesome that it will handle all the OAuth 2.0 callbacks, authorization, and token requests.

Extra note:
By following the above approach we are able to remove thelinkedin_url form ER and class diagrams.

Milestone deadline: 2020-08-15T18:29:00Z

WDY guys think about this approach?

1 Like

Would there be an alternative way to sign-up?

No since we decided to have Linkedin as the CV for users, Itā€™s a must to have a Linkedin account. So we decided it will be ok to provide just the Linkedin sign-in.

It is a risky assumption though. There could be people who do not have a LinkedIn profile. But for now letā€™s use this, as it is convenient.

Yeah and Spring boot provides spring-boot-starter-social dependencies for Facebook and Twitter so we can implement support for those platforms easily.
And I think itā€™s possible to provide support for other platforms as well(Google, etc.) but need to do some research on this.

1 Like

There are a few major changes that should be noted on the above PR.

Unfortunately, I couldnā€™t use the quoted dependency, as itā€™s been deprecated since the end of 2019 [1]. So as a solution I used spring-boot-starter-security with spring-security-oauth2-client [2].
This way we will be able to provide log-in using any provider that supports OAuth or OpenID(Facebook, GitHub, Google, etc.)

The above PR only covers authenticating users against Linkedin OAuth. And will be making separate PR for the below issue:
Requirements: JPA Entities have to be completed

@DevTeam please send me your Linkedin accounts to add you to the SEF application.


  1. https://spring.io/blog/2018/07/03/spring-social-end-of-life-announcement#:~:text=Today%20it%20is%20with%20an,over%20the%20past%20eight%20years. ā†©ļøŽ

  2. https://spring.io/blog/2018/03/06/using-spring-security-5-to-integrate-with-oauth-2-secured-services-such-as-facebook-and-github ā†©ļøŽ

1 Like

For the current sprint, I am assigned to continue this task. Iā€™m doing the LinkedIn authentication part and meanwhile, @Gravewalker is continuing the Kubernetes integration.

I and @YohanAvishke had a discussion on the user authentication today.
Here are the main points we discussed.

  • @YohanAvishke had already done most of the LinkedIn authentication in the same module before (in this pull request.)
  • We should create a new module under ScholarX backend for the auth-server
  • And add necessary configurations to authenticate a Linkedin user
  • Add the functionality to persist user details in the database
  • Integrate it with the Kubernetes cluster

In addition to that, we discussed to change the .properties files to .yml for a clean code

Btw, I hope to complete up to LinkedIn authentication part and send the pull request before 2021-01-07T18:29:00Z

2 Likes

Merged the PR containing the modularisation. Good job @piumal1999

Sent the PR for saving users to database. Please review and merge

This PR is merged now.
When a user goes to a page which needs authorization, it will redirect the user to linkedin login page, and taken back to the same page after the user login and authorize the app. An access token is created and kept in the session when a user log in correctly. the token will be available for 2 months.

For testing and developing, the redirect uri have to be added to the Authorized redirect URLs list in linkedin developer dashboard because it depends on the ip.

1 Like

Good job @piumal1999 :heart:
@Gravewalker the DB issue you were facing is fixed now. And if there are any redirection failures just add the IP to the list of secure links list in,
https://www.linkedin.com/developers/apps/72779526/auth
Let us know how the tokens will be generated and handled in the gateway service. And if you face any issues just contact me or @piumal1999

We had a discussion on the next steps of the authentication module of ScholarX 2021-02-01T08:00:00Z.

Attendees: @jaye @YohanAvishke @Gravewalker @piumal1999

We discussed to do several changes to the current auth-server module in order to get a working product.

In the current version, after a user logs in, he/she will be redirected to the the previous page automatically by the spring boot default configuration. So we canā€™t just use it as it is because we need to integrate it with the app module.

So we discussed to remove the automatic redirection. The app module will be used as the resource server and the auth-server will be used as the authentication server. So every request from the frontend should go through the auth-server. (The app module should not be accessible directly)
And the permissions for each endpoint have to be set on the security configurations of auth-server.

Example:

An endpoint we already use in backend and frontend:
GET {app-module-ip}/admin/programs

  • In the app module, it wonā€™t change.
  • In the frontend, an prefix like /auth/ need be added to the endpoint. ({auth-server-ip}/auth/admin/programs)
  • In the auth-server we need to create a new controller for /auth path.And add it to security configurations as a path which needs authentication.

In that controller, it should extract the url (removing the prefix) and send a http request with the relevant data to app module.

Btw, i wonā€™t be available for few weeks due to my exams. So @anjisvj @miluckshan-j could you also have a look on this.

1 Like

Hi @piumal1999,

Thanks for the update. I just entered the game! ā€¦and completed the ā€œinvokerā€ functionality (the term that I forgot :sweat_smile:) I will try to finalize the login as well.

2 Likes

Hi everyone,
In the previous standup meetings, it was stated that there was an error in the /me endpoint when using it with the frontend (But worked when calling using directly). As i can remember, the error was a 500 Internal server error with an null point exception. To reproduce it, i set up the backend and frontend in my local machine but in there, it worked properly. Iā€™ll briefly tell how i setup it so you can try it and let me know if something is wrong.

  1. Cloned both repos.(master branches)

  2. Replaced endpoint URLs in frontend according to the backend because its running on a differnet port (localhost:8080/ ā€”> localhost:8080/api/)

  3. Updated the resources/application.yml in backend (client-id, client-secret, datasource details)

  4. Deployed the frontend (port:3000) and the backend(port:8080)

  5. Navigated to the homepage of frontend (with CORS enabled)
    image
    Here, a 403 error occurs with /me endpoit because a user havenā€™t logged in

  6. Navigated to the auth url http://localhost:8080/oauth2/authorization/linkedin using a different tab and authenticated from linkedin (can link it with sign up botton). After loggin in, it redirects to http://localhost:8080/. I think we have to change the redirection URI on backend configuration to rdirect it to the frontend.

  7. Reloaded the home page
    image

There were no any 500 errors. image

So i couldnā€™t reproduce that error. Maybe the error was due to some database errors. I used my previous database which had some sample data. Hereā€™s the profile generated when logging.(I changed the image url btw)
image

cc: @YohanAvishke @jaye @anjisvj @Gravewalker @EngTeam

Good job @piumal1999 Thanks for the update. Iā€™ll follow your steps and see if I can reproduce the error on my local instance. Iā€™ll give an update by the end of the day. If I find no errors it means that we can simply deploy the app in 2 heroku dinos right?

Yeah @piumal1999 your were right, even I did the same thing and setup the project and itā€™s working without any errors. @anjisvj @jaye what exactly was the error that you guys encountered the other day? If you guys can recall.

I checked it by deploying the front-end and backend using heroku.
The session is created only in the backend when a user login through the authorization uri. So we have to find a way to pass the created session to the frontend domain.
(And, if we deploy the frontend and backend in different ports of same domain, it will work properly like we saw in the localhost)
Am i right? @YohanAvishke

I changed the redirection uri of the authentication service to redirect to the frontend after logging. But it creates the JSESSIONID cookie in the backend itself before the redirection.

In most of the stackoverflow threads i read, it was said that using the same domain with different ports like we did in localhost would fix the issue. But in heroku, we canā€™t open two ports.(But possible to create subdomains)

Also i tried changing the cookie domain through the application.yml file. But it throws a 500 error with java.lang.IllegalArgumentException: An invalid domain [scholarx-frontend.herokuapp.com] was specified for this cookie
I think it doesnā€™t provide the ability to create cookies in other domains.
Creating a cookie manually using a cookie editor plugin didnā€™t solved the issue either.

Asked in stackoverflow too:

Is it working locally? If yes, I donā€™t think it wonā€™t be a problem in deployment since we are planing to use EC2.

It works when running in the localhost. So we can run it in the ec2 instance without that error.

1 Like