Jump to content

Basic page access using OAuth Google authentication

(reposting this in the Programming section because I realized it probably belongs here and didn't get any responses, sorry mods if this isn't allowed)

 

I have little to no experience with web development so far so I've just been reading up on minimal documentation to accomplish the project I'm working on. However, some of the data on the page/server is sensitive to my organization (Google Apps-based) so I'd like to set up a simple login page that only accepts Google accounts ending with @organization.org which will then grant access to the main HTML page. This thread seemed to be promising:

 

Restrict Login Email with Google OAuth2.0 to Specific Domain Name

 

But I'm not sure how to even setup a login page at all, regardless of domain-restricting. I wasn't able to find any OAuth documentation to help me with this either. Is this something that OAuth can do? Also, is there any way I should be setting permissions/restricting access to the actual files (such as my main .json data file) to prevent unintended access?

Edited by colonel_mortis
Day theme friendly
Link to comment
Share on other sites

Link to post
Share on other sites

Generally, it's best to find a library that does it for you. The basic idea is as follows:

Login page -> Click "Sign in with Google" -> Redirect to Google OAuth page -> Accept -> Return to "Callback URL," like example.com/google/callback, with an object that represents the user -> Check if the user email ends with what you want it to -> Store user session

For Google, you'll need to go to console.cloud.google.com, create a new project, and add (if i recall correctly), the Google+ API. Then customize your OAuth page, create some credentials, and use those to authorize an OAuth request, again, easier with a library like PassportJS for NodeJS. Then set up a callback, both on your server and in the Cloud Console, and parse the data after a user logs in.

˙ǝɯᴉʇ ɹnoʎ ƃuᴉʇsɐʍ ǝɹɐ noʎ 'sᴉɥʇ pɐǝɹ oʇ ƃuᴉʎɹʇ ǝɹɐ noʎ ɟI

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, dannytech357 said:

Generally, it's best to find a library that does it for you. The basic idea is as follows:

Login page -> Click "Sign in with Google" -> Redirect to Google OAuth page -> Accept -> Return to "Callback URL," like example.com/google/callback, with an object that represents the user -> Check if the user email ends with what you want it to -> Store user session

For Google, you'll need to go to console.cloud.google.com, create a new project, and add (if i recall correctly), the Google+ API. Then customize your OAuth page, create some credentials, and use those to authorize an OAuth request, again, easier with a library like PassportJS for NodeJS. Then set up a callback, both on your server and in the Cloud Console, and parse the data after a user logs in.

In concept that seems doable, but I wouldn't even know where to start. Is there any documentation I could follow?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×