Skip to content

Commit edef5d2

Browse files
updates for local testing - examples in local scripts
Signed-off-by: Łukasz Gryglicki <[email protected]>
1 parent 18931a2 commit edef5d2

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

cla-backend-go/auth/authorizer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (a Authorizer) SecurityAuth(token string, scopes []string) (*user.CLAUser,
8989
}
9090
f["username"] = username
9191

92+
// LG: to allow local testing
93+
// a.authValidator.nameClaim = "http://lfx.dev/claims/username"
94+
// a.authValidator.emailClaim = "http://lfx.dev/claims/email"
95+
9296
nameClaim, ok := claims[a.authValidator.nameClaim]
9397
if !ok {
9498
log.WithFields(f).Warnf("name not found: %+v", a.authValidator.nameClaim)

cla-backend-go/cmd/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ func server(localMode bool) http.Handler {
235235
log.WithFields(f).WithError(err).Panic("unable to setup docraptor client")
236236
}
237237

238+
// LG: to test with manual tokens
239+
// configFile.Auth0.UsernameClaim = "http://lfx.dev/claims/username"
238240
authValidator, err := auth.NewAuthValidator(
239241
configFile.Auth0.Domain,
240242
configFile.Auth0.ClientID,

cla-backend/cla/auth.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import cla
1313

14+
# LG: for local environment override
15+
# os.environ["AUTH0_USERNAME_CLAIM"] = os.getenv("AUTH0_USERNAME_CLAIM_CLI", os.environ["AUTH0_USERNAME_CLAIM"])
16+
1417
auth0_base_url = os.environ.get('AUTH0_DOMAIN', '')
1518
auth0_username_claim = os.environ.get('AUTH0_USERNAME_CLAIM', '')
1619
algorithms = [os.environ.get('AUTH0_ALGORITHM', '')]
@@ -95,6 +98,8 @@ def authenticate_user(headers):
9598
"n": key["n"],
9699
"e": key["e"]
97100
}
101+
# print("Token kid:", unverified_header["kid"])
102+
# print("JWKS kids:", [key["kid"] for key in jwks["keys"]])
98103
if rsa_key:
99104
try:
100105
payload = jwt.decode(
@@ -118,7 +123,9 @@ def authenticate_user(headers):
118123

119124
username = payload.get(auth0_username_claim)
120125
if username is None:
121-
raise AuthError('username not found')
126+
# LG: to have more info
127+
# raise AuthError(f"username not found in {auth0_username_claim}")
128+
raise AuthError('username claim not found')
122129

123130
auth_user = AuthUser(payload)
124131

utils/get_user_from_token_go.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# API_URL=https://api.lfcla.dev.platform.linuxfoundation.org
44
# DEBUG='' ./utils/get_user_from_token_go.sh
55
# Note: To run manually see cla-backend-go/auth/authorizer.go:SecurityAuth() and update accordingly 'LG:'
6+
# Or generate a real token using ... and the edit 'cla-backend-go/cmd/server.go' - look for "LG: to test with manual tokens"
7+
# Or to get a real user data:
8+
# on local (non remote) computer: ~/get_oauth_token.sh (or ~/get_oauth_token_prod.sh) (will open browser, authenticate to LF, and return token data)
9+
# edit 'cla-backend-go/cmd/server.go' - look for "LG: to test with manual tokens", then 'cla-backend-go/auth/authorizer.go': LG: to allow local testing", then run ./bin/cla
10+
# then TOKEN='value from the get_oauth_token.sh script' DEBUG='' ./utils/get_user_from_token_go.sh
611

712
if [ -z "$TOKEN" ]
813
then

0 commit comments

Comments
 (0)