Skip to content

Commit 9320f1c

Browse files
committed
fix(server): add flow comment
1 parent c095580 commit 9320f1c

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

server/handlers/authorize.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
package handlers
22

3+
/**
4+
LOGIC TO REMEMBER THE AUTHORIZE FLOW
5+
6+
7+
jargons
8+
`at_hash` -> access_token_hash
9+
`c_hash` -> code_hash
10+
11+
12+
# ResponseType: Code
13+
with /authorize request
14+
- set state [state, code@@challenge]
15+
- add &code to login redirect url
16+
login resolver has optional param state
17+
-if state found in store, split with @@
18+
- if len > 1 -> response type is code and has code + challenge
19+
- set `nonce@@code` for createAuthToken request so that `c_hash` can be generated
20+
- do not add `nonce` to id_token in code flow, instead set `c_hash` and `at_hash`
21+
22+
23+
# ResponseType: token / id_token
24+
with /authorize request
25+
- set state [state, nonce]
26+
- add &nonce to login redirect url
27+
login resolver has optional param state
28+
- if state found in store, split with @@
29+
- if len < 1 -> response type is token / id_token and has nonce
30+
- send received nonce for createAuthToken
31+
- set `nonce` and `at_hash` in `id_token`
32+
**/
33+
334
import (
435
"fmt"
536
"net/http"
@@ -19,21 +50,22 @@ import (
1950
"github.com/authorizerdev/authorizer/server/utils"
2051
)
2152

22-
// AuthorizeHandler is the handler for the /authorize route
23-
// required params
24-
// ?redirect_uri = redirect url
25-
// ?response_mode = to decide if result should be html or re-direct
26-
// state[recommended] = to prevent CSRF attack (for authorizer its compulsory)
27-
// code_challenge = to prevent CSRF attack
28-
// code_challenge_method = to prevent CSRF attack [only sh256 is supported]
53+
// Check the flow for generating and verifying codes: https://developer.okta.com/blog/2019/08/22/okta-authjs-pkce#:~:text=PKCE%20works%20by%20having%20the,is%20called%20the%20Code%20Challenge.
2954

30-
// check the flow for generating and verifying codes: https://developer.okta.com/blog/2019/08/22/okta-authjs-pkce#:~:text=PKCE%20works%20by%20having%20the,is%20called%20the%20Code%20Challenge.
55+
// Check following docs for understanding request / response params for various types of requests: https://auth0.com/docs/authenticate/login/oidc-conformant-authentication/oidc-adoption-auth-code-flow
3156

3257
const (
3358
authorizeWebMessageTemplate = "authorize_web_message.tmpl"
3459
authorizeFormPostTemplate = "authorize_form_post.tmpl"
3560
)
3661

62+
// AuthorizeHandler is the handler for the /authorize route
63+
// required params
64+
// ?redirect_uri = redirect url
65+
// ?response_mode = to decide if result should be html or re-direct
66+
// state[recommended] = to prevent CSRF attack (for authorizer its compulsory)
67+
// code_challenge = to prevent CSRF attack
68+
// code_challenge_method = to prevent CSRF attack [only sh256 is supported]
3769
func AuthorizeHandler() gin.HandlerFunc {
3870
return func(gc *gin.Context) {
3971
redirectURI := strings.TrimSpace(gc.Query("redirect_uri"))

0 commit comments

Comments
 (0)