Skip to content

Commit 35ab2a2

Browse files
yannicktrinhKyleKincer
authored andcommitted
Add support for custom state and nonce parameters in OAuth2 authorization
- Add optional state parameter support to OAuth2Provider constructor - Add optional nonce parameter support to OAuth2Provider constructor - Use custom state parameter if provided, otherwise generate UUID (maintains backward compatibility) - Include nonce parameter in authorization URL when provided - Both parameters are properly URL-encoded for security This enables developers to: - Pass custom state values for enhanced CSRF protection - Include nonce parameter for OpenID Connect ID token verification - Maintain existing behavior when parameters are not provided Note: The existing commented-out state verification code should be uncommented and updated to properly validate returned state parameters.
1 parent a0a7613 commit 35ab2a2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Project/Sources/Classes/OAuth2Provider.4dm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ Any valid existing token
8989
This:C1470.timeout:=Choose:C955(Value type:C1509($inParams.timeout)=Is undefined:K8:13; 120; Num:C11($inParams.timeout))
9090

9191
End if
92-
92+
/*
93+
A unique string value that is used to maintain state between the request and response. Can be used to mitigate CSRF attacks.
94+
*/
95+
This:C1470.state:=String:C10($inParams.state)
96+
97+
/*
98+
A random value used by the app to verify the ID token. Used to prevent replay attacks.
99+
*/
100+
This:C1470.nonce:=String:C10($inParams.nonce)
101+
93102
This:C1470._finally()
94103

95104

@@ -99,9 +108,10 @@ Any valid existing token
99108

100109
Function _OpenBrowserForAuthorisation()->$authorizationCode : Text
101110

102-
var $url; $redirectURI; $state; $scope : Text
111+
var $url; $redirectURI; $state; $scope; $nonce : Text
103112

104-
$state:=Generate UUID:C1066
113+
$state:=Choose:C955(Length:C16(This:C1470.state)>0; This:C1470.state; Generate UUID:C1066)
114+
$nonce:=This:C1470.nonce
105115
$redirectURI:=This:C1470.redirectURI
106116
$url:=This:C1470.authenticateURI
107117
$scope:=This:C1470.scope
@@ -134,7 +144,9 @@ Function _OpenBrowserForAuthorisation()->$authorizationCode : Text
134144
$url+="&scope="+_urlEscape($scope)
135145
End if
136146
$url+="&state="+String:C10($state)
137-
147+
If (Length:C16(String:C10($nonce))>0)
148+
$url+="&nonce="+_urlEscape($nonce)
149+
End if
138150
Use (Storage:C1525)
139151
OB REMOVE:C1226(Storage:C1525; "token")
140152
Storage:C1525.params:=New shared object:C1526("redirectURI"; $redirectURI)

0 commit comments

Comments
 (0)