Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oidc-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Synced
Oidc-lib
Commits
0aa61b0b
Unverified
Commit
0aa61b0b
authored
5 months ago
by
Tim Möhlmann
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(op): do not redirect to unverified uri on error (#640)
Closes #627
parent
de034c8d
No related branches found
Branches containing commit
Tags
v3.27.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/op/auth_request.go
+30
-16
30 additions, 16 deletions
pkg/op/auth_request.go
with
30 additions
and
16 deletions
pkg/op/auth_request.go
+
30
−
16
View file @
0aa61b0b
...
...
@@ -83,19 +83,27 @@ func Authorize(w http.ResponseWriter, r *http.Request, authorizer Authorizer) {
if
authReq
.
RequestParam
!=
""
&&
authorizer
.
RequestObjectSupported
()
{
err
=
ParseRequestObject
(
ctx
,
authReq
,
authorizer
.
Storage
(),
IssuerFromContext
(
ctx
))
if
err
!=
nil
{
AuthRequestError
(
w
,
r
,
authReq
,
err
,
authorizer
)
AuthRequestError
(
w
,
r
,
nil
,
err
,
authorizer
)
return
}
}
if
authReq
.
ClientID
==
""
{
AuthRequestError
(
w
,
r
,
authReq
,
fmt
.
Errorf
(
"auth request is missing client_id"
),
authorizer
)
AuthRequestError
(
w
,
r
,
nil
,
fmt
.
Errorf
(
"auth request is missing client_id"
),
authorizer
)
return
}
if
authReq
.
RedirectURI
==
""
{
AuthRequestError
(
w
,
r
,
authReq
,
fmt
.
Errorf
(
"auth request is missing redirect_uri"
),
authorizer
)
AuthRequestError
(
w
,
r
,
nil
,
fmt
.
Errorf
(
"auth request is missing redirect_uri"
),
authorizer
)
return
}
validation
:=
ValidateAuthRequest
var
client
Client
validation
:=
func
(
ctx
context
.
Context
,
authReq
*
oidc
.
AuthRequest
,
storage
Storage
,
verifier
*
IDTokenHintVerifier
)
(
sub
string
,
err
error
)
{
client
,
err
=
authorizer
.
Storage
()
.
GetClientByClientID
(
ctx
,
authReq
.
ClientID
)
if
err
!=
nil
{
return
""
,
oidc
.
ErrInvalidRequestRedirectURI
()
.
WithDescription
(
"unable to retrieve client by id"
)
.
WithParent
(
err
)
}
return
ValidateAuthRequestClient
(
ctx
,
authReq
,
client
,
verifier
)
}
if
validater
,
ok
:=
authorizer
.
(
AuthorizeValidator
);
ok
{
validation
=
validater
.
ValidateAuthRequest
}
...
...
@@ -113,11 +121,6 @@ func Authorize(w http.ResponseWriter, r *http.Request, authorizer Authorizer) {
AuthRequestError
(
w
,
r
,
authReq
,
oidc
.
DefaultToServerError
(
err
,
"unable to save auth request"
),
authorizer
)
return
}
client
,
err
:=
authorizer
.
Storage
()
.
GetClientByClientID
(
ctx
,
req
.
GetClientID
())
if
err
!=
nil
{
AuthRequestError
(
w
,
r
,
req
,
oidc
.
DefaultToServerError
(
err
,
"unable to retrieve client by id"
),
authorizer
)
return
}
RedirectToLogin
(
req
.
GetID
(),
client
,
w
,
r
)
}
...
...
@@ -212,26 +215,37 @@ func CopyRequestObjectToAuthRequest(authReq *oidc.AuthRequest, requestObject *oi
authReq
.
RequestParam
=
""
}
// ValidateAuthRequest validates the authorize parameters and returns the userID of the id_token_hint if passed
// ValidateAuthRequest validates the authorize parameters and returns the userID of the id_token_hint if passed.
//
// Deprecated: Use [ValidateAuthRequestClient] to prevent querying for the Client twice.
func
ValidateAuthRequest
(
ctx
context
.
Context
,
authReq
*
oidc
.
AuthRequest
,
storage
Storage
,
verifier
*
IDTokenHintVerifier
)
(
sub
string
,
err
error
)
{
ctx
,
span
:=
tracer
.
Start
(
ctx
,
"ValidateAuthRequest"
)
defer
span
.
End
()
authReq
.
MaxAge
,
err
=
ValidateAuthReqPrompt
(
authReq
.
Prompt
,
authReq
.
MaxAge
)
client
,
err
:
=
storage
.
GetClientByClientID
(
ctx
,
authReq
.
ClientID
)
if
err
!=
nil
{
return
""
,
oidc
.
ErrInvalidRequestRedirectURI
()
.
WithDescription
(
"unable to retrieve client by id"
)
.
WithParent
(
err
)
}
return
ValidateAuthRequestClient
(
ctx
,
authReq
,
client
,
verifier
)
}
// ValidateAuthRequestClient validates the Auth request against the passed client.
// If id_token_hint is part of the request, the subject of the token is returned.
func
ValidateAuthRequestClient
(
ctx
context
.
Context
,
authReq
*
oidc
.
AuthRequest
,
client
Client
,
verifier
*
IDTokenHintVerifier
)
(
sub
string
,
err
error
)
{
ctx
,
span
:=
tracer
.
Start
(
ctx
,
"ValidateAuthRequestClient"
)
defer
span
.
End
()
if
err
:=
ValidateAuthReqRedirectURI
(
client
,
authReq
.
RedirectURI
,
authReq
.
ResponseType
);
err
!=
nil
{
return
""
,
err
}
client
,
err
:
=
storage
.
GetClientByClientID
(
ctx
,
authReq
.
ClientID
)
authReq
.
MaxAge
,
err
=
ValidateAuthReqPrompt
(
authReq
.
Prompt
,
authReq
.
MaxAge
)
if
err
!=
nil
{
return
""
,
oidc
.
DefaultToServerError
(
err
,
"unable to retrieve client by id"
)
return
""
,
err
}
authReq
.
Scopes
,
err
=
ValidateAuthReqScopes
(
client
,
authReq
.
Scopes
)
if
err
!=
nil
{
return
""
,
err
}
if
err
:=
ValidateAuthReqRedirectURI
(
client
,
authReq
.
RedirectURI
,
authReq
.
ResponseType
);
err
!=
nil
{
return
""
,
err
}
if
err
:=
ValidateAuthReqResponseType
(
client
,
authReq
.
ResponseType
);
err
!=
nil
{
return
""
,
err
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment