This is my practice repo to learn about creating backend stuff & openid connect authentication stuff in golang.
-
install golang
-
$git clone https://github.com/coding-CEO/go-backend-test.git
-
create .env file in root directory and set following values,
GOOGLE_OAUTH2_CLIENT_ID={YOUR CLIENT ID} GOOGLE_OAUTH2_CLIENT_SECRET={YOUR CLIENT SECRET}
-
$go run main.go
-
server should start now
- start server
- call GET /googleGenerateUserOAuthCode API by setting request as mentioned in below API table from front-end, you will get google oauth url
- redirect front-end to that url
- perform google login
- google will redirct to specific url that you set in step 2
- call GET /googleVerifyUserOAuthCode by setting request as mentioned in below API table from front-end
- you will get JWT of your google account
This is the basic design of what I want to build.
Authenticate users of clients using single authentication-service-provider
Clients: ┌────> a.com b.in c.org <───────┐
│ ↓ ↓ ↓ │
Front-End Repo: │ ┌───> login/signup interface <────┐ |
│ │ ↓ │ │
This Repo: │ └─ authentication-service-provider ─┘ │
│ ↓ ↓ ↓ │
OAuth Servers: └─ google.com apple.com facebook.com ─┘
Route | Type | body | output body | req. cookie | resp. cookie | urlParams | req. extras | details |
---|---|---|---|---|---|---|---|---|
/verifyUser | GET | - | - | token | - | - | - | This will verify the token from cookie and pass to next handler function. otherwise redirect to a central login page |
/googleGenerateUserOAuthCode | GET | - | googleOAuthRedirectUrl | - | Set-Cookie:state={xyz}, Set-Cookie:nonce={xyz} | targetRedirectUrl | set {withCredentials: true} | set verification cookies (state, nonce) and returns google oauth url(GOU) then front-end should redirect to GOU then GOU will automatically redirect to targetRedirectUrl where code(OAuth code) param will automatically get attached |
/googleVerifyUserOAuthCode | GET | - | {JWT: 'xyz'} | state, nonce | - | state, code | set {withCredentials: true} | verify the state from params & cookie, then verify the code(OAuth code) in the params, then verify nonce from idToken, then generate JWT and return as JSON. (maybe perform user registration in database here) |
- implement code_challenge stuff
- maybe change the flow to reduce effort on front-end side
- something else that will popup out of nowhere