Skip to content

Commit

Permalink
[NetKit] OAuth 2.0 PKCE
Browse files Browse the repository at this point in the history
Jobs:GitHub:4020
  • Loading branch information
yannicktrinh committed Jan 22, 2024
1 parent 743e91d commit 8574861
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
31 changes: 16 additions & 15 deletions Project/Sources/Classes/OAuth2Provider.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,13 @@ Class constructor($inParams : Object)
See https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce
*/
This.PKCEEnabled:=Bool($inParams.PKCEEnabled)
/*
If (This.PKCEEnabled)
If ((String($inParams.PKCEMethod)="plain") || \
(String($inParams.PKCEMethod)="S256"))
If ((String($inParams.PKCEMethod)="plain") || (String($inParams.PKCEMethod)="S256"))
This.PKCEMethod:=String($inParams.PKCEMethod)
Else
This.PKCEMethod:="S256" // Default PKCEMethod
End if
End if
*/
End if
End if

This._finally()
Expand Down Expand Up @@ -314,7 +311,7 @@ Function _OpenBrowserForAuthorisation()->$authorizationCode : Text
: (This._isMicrosoft() && (Length(String(This.tenant))=0))
This._throwError(2; {attribute: "tenant"})

: (This._isSignedIn() & (Length(String($redirectURI))=0))
: (This._isSignedIn() && (Length(String($redirectURI))=0))
This._throwError(2; {attribute: "redirectURI"})

Else
Expand Down Expand Up @@ -353,15 +350,15 @@ Function _OpenBrowserForAuthorisation()->$authorizationCode : Text

var $endTime : Integer
$endTime:=Milliseconds+(This.timeout*1000)
While ((Milliseconds<=$endTime) & (Not(OB Is defined(Storage.requests[$state]; "token")) | (Storage.requests[$state].token=Null)))
While ((Milliseconds<=$endTime) && (Not(OB Is defined(Storage.requests[$state]; "token")) | (Storage.requests[$state].token=Null)))
DELAY PROCESS(Current process; 10)
End while

Use (Storage.requests)
If (OB Is defined(Storage.requests; $state))
Use (Storage.requests[$state])
$authorizationCode:=Storage.requests[$state].token.code
//If (OB Is defined(Storage.requests[$state].token; "state") & (Length(OB Get(Storage.requests[$state].token; "state"; Is text))>0))
//If (OB Is defined(Storage.requests[$state].token; "state") && (Length(OB Get(Storage.requests[$state].token; "state"; Is text))>0))
//ASSERT(Storage.requests[$state].token.state=$state; "state changed !!! CSRF Attack ?")
//End if

Expand Down Expand Up @@ -551,7 +548,7 @@ Function _checkPrerequisites($obj : Object)->$OK : Boolean

$OK:=False

If (($obj#Null) & (Value type($obj)=Is object))
If (($obj#Null) && (Value type($obj)=Is object))

Case of

Expand All @@ -564,10 +561,10 @@ Function _checkPrerequisites($obj : Object)->$OK : Boolean
: (Length(String($obj.permission))=0)
This._throwError(2; {attribute: "permission"})

: (Not(String($obj.permission)="signedIn") & Not(String($obj.permission)="service"))
: (Not(String($obj.permission)="signedIn") && Not(String($obj.permission)="service"))
This._throwError(3; {attribute: "permission"})

: ((String($obj.permission)="signedIn") & (Length(String($obj.redirectURI))=0))
: ((String($obj.permission)="signedIn") && (Length(String($obj.redirectURI))=0))
This._throwError(2; {attribute: "redirectURI"})

Else
Expand Down Expand Up @@ -771,10 +768,10 @@ Function getToken()->$result : Object
: (Length(String(This.permission))=0)
This._throwError(2; {attribute: "permission"})

: (This._isSignedIn() & (Length(String($redirectURI))=0))
: (This._isSignedIn() && (Length(String($redirectURI))=0))
This._throwError(2; {attribute: "permission"})

: (Not(This._isSignedIn()) & Not(This._isService()))
: (Not(This._isSignedIn()) && Not(This._isService()))
This._throwError(3; {attribute: "permission"})

Else
Expand All @@ -788,11 +785,15 @@ Function getToken()->$result : Object

$result:=This._getToken_SignedIn($bUseRefreshToken)

Else
: (This._isService())

$result:=This._getToken_Service()

End case
Else

This._throwError(3; {attribute: "permission"})

End case

If ($result#Null)
// Save token internally
Expand Down
8 changes: 4 additions & 4 deletions Project/Sources/Classes/OAuth2Token.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class constructor($inParams : Object)
var $params : Object
$params:=Null
If (Count parameters>0)
If ((Type($inParams)=Is object) & (Not(OB Is empty($inParams))))
If ((Type($inParams)=Is object) && (Not(OB Is empty($inParams))))
$params:=$inParams
End if
End if
Expand All @@ -24,7 +24,7 @@ Class constructor($inParams : Object)

Function _loadFromObject($inObject : Object)

If (($inObject#Null) & (Not(OB Is empty($inObject))))
If (($inObject#Null) && (Not(OB Is empty($inObject))))

This.token:={}
If (OB Get type($inObject; "token")=Is object)
Expand Down Expand Up @@ -62,7 +62,7 @@ Function _loadFromResponse($inResponseString : Text)
var $token : Object

$token:=JSON Parse($inResponseString)
If (($token#Null) & (Not(OB Is empty($token))))
If (($token#Null) && (Not(OB Is empty($token))))

This._loadFromObject({token: $token})

Expand Down Expand Up @@ -108,7 +108,7 @@ Function _Expired($inParams : Text)->$result : Boolean
Case of
: (Current date<Date($expiration))
$result:=False
: ((Current date=Date($expiration)) & \
: ((Current date=Date($expiration)) && \
((Current time+0)<(Time($expiration)+0)))
$result:=False
End case
Expand Down
2 changes: 1 addition & 1 deletion Project/Sources/Classes/_GraphAPI.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Function _copyGraphMessage($inMessage : Object) : Object

Function _loadFromObject($inObject : Object)

If (($inObject#Null) & (Not(OB Is empty($inObject))))
If (($inObject#Null) && (Not(OB Is empty($inObject))))

var $key : Text
var $keys : Collection
Expand Down
2 changes: 1 addition & 1 deletion Project/Sources/Methods/_getParameterValue.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ If (Match regex($pattern; $headerValue; 1; $foundPosArr; $foundLenArr))
End if
End if
End if
If (($startPos>0) & ($endPos>$startPos))
If (($startPos>0) && ($endPos>$startPos))
$paramValue:=Substring($headerValue; $startPos; $endPos-$startPos)
End if
2 changes: 1 addition & 1 deletion Project/Sources/Methods/_startWebServer.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ End if

$webServer:=WEB Server(Web server database)

If ($webServer.isRunning & (($webServer.HTTPPort#$settings.HTTPPort) || \
If ($webServer.isRunning && (($webServer.HTTPPort#$settings.HTTPPort) || \
($webServer.debugLog#$settings.debugLog)))

$webServer.stop()
Expand Down
6 changes: 3 additions & 3 deletions Project/Sources/Methods/_urlEncode.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ For ($i; 1; $length)
Case of
: ($code=45)
: ($code=46)
: ($code>47) & ($code<58)
: ($code>63) & ($code<91)
: ($code>47) && ($code<58)
: ($code>63) && ($code<91)
: ($code=95)
: ($code>96) & ($code<123)
: ($code>96) && ($code<123)
: ($code=126)
Else
$shouldEscape:=True
Expand Down

0 comments on commit 8574861

Please sign in to comment.