|
3 | 3 |
|
4 | 4 | var $redirectURI : Text |
5 | 5 | var $URL : Text:=$inOptions.redirectURI |
6 | | -var $customResponseFile; $customErrorFile : 4D.File |
| 6 | +var $authenticationPage; $authenticationErrorPage : Variant |
7 | 7 | var $state : Text:=String($inOptions.state) |
8 | | -var $responseFile : 4D.File:=Folder(fk resources folder).file("responseTemplate.html") |
9 | 8 |
|
10 | 9 | If (OB Is defined(Storage.requests; $state)) |
11 | 10 | $redirectURI:=String(Storage.requests[$state].redirectURI) |
12 | 11 | If (Length($redirectURI)>0) |
13 | 12 | $redirectURI:=cs.Tools.me.getPathFromURL($redirectURI)+"@" |
14 | 13 | End if |
15 | | - $customResponseFile:=(Value type(Storage.requests[$state].authenticationPage)#Is undefined) ? Storage.requests[$state].authenticationPage : Null |
16 | | - $customErrorFile:=(Value type(Storage.requests[$state].authenticationErrorPage)#Is undefined) ? Storage.requests[$state].authenticationErrorPage : Null |
| 14 | + $authenticationPage:=(Value type(Storage.requests[$state].authenticationPage)#Is undefined) ? Storage.requests[$state].authenticationPage : Null |
| 15 | + $authenticationErrorPage:=(Value type(Storage.requests[$state].authenticationErrorPage)#Is undefined) ? Storage.requests[$state].authenticationErrorPage : Null |
17 | 16 | End if |
18 | 17 |
|
19 | 18 | If ($URL=$redirectURI) |
20 | 19 |
|
| 20 | + var $responseFile : 4D.File:=Null |
| 21 | + var $responseRedirectURI : Text:="" |
| 22 | + var $customPageObject : Object:=Null |
21 | 23 | var $pageTitle; $pageMessage; $pageDetails : Text |
22 | 24 |
|
23 | 25 | If (OB Is defined(Storage.requests; $state)) |
@@ -45,24 +47,57 @@ If ($URL=$redirectURI) |
45 | 47 | End if |
46 | 48 | $pageDetails:=Localized string("OAuth2_Response_Details") |
47 | 49 |
|
48 | | - $responseFile:=($customErrorFile#Null) ? $customErrorFile : $responseFile |
| 50 | + If (Value type($authenticationErrorPage)=Is text) |
| 51 | + $responseRedirectURI:=String($authenticationErrorPage) |
| 52 | + Else |
| 53 | + $customPageObject:=($authenticationErrorPage#Null) ? $authenticationErrorPage : Folder(fk resources folder).file("responseTemplate.html") |
| 54 | + If (OB Instance of($customPageObject; 4D.File)) |
| 55 | + $responseFile:=$customPageObject |
| 56 | + End if |
| 57 | + End if |
49 | 58 | Else |
50 | 59 |
|
51 | 60 | $pageTitle:=Localized string("OAuth2_Response_Title") |
52 | 61 | $pageMessage:=Localized string("OAuth2_Response_Message") |
53 | 62 | $pageDetails:=Localized string("OAuth2_Response_Details") |
54 | 63 |
|
55 | | - $responseFile:=($customResponseFile#Null) ? $customResponseFile : $responseFile |
| 64 | + If (Value type($authenticationPage)=Is text) |
| 65 | + $responseRedirectURI:=String($authenticationPage) |
| 66 | + Else |
| 67 | + $customPageObject:=($authenticationPage#Null) ? $authenticationPage : Folder(fk resources folder).file("responseTemplate.html") |
| 68 | + If (OB Instance of($customPageObject; 4D.File)) |
| 69 | + $responseFile:=$customPageObject |
| 70 | + End if |
| 71 | + End if |
56 | 72 | End if |
57 | 73 |
|
58 | | - var $responseFileContent : Text:=$responseFile.getText() |
59 | | - var $outResponseBody : Text:="" |
60 | | - |
61 | | - PROCESS 4D TAGS($responseFileContent; $outResponseBody; $pageTitle; $pageMessage; $pageDetails) |
62 | | - |
63 | | - $outResponse.status:=200 |
64 | | - $outResponse.body:=$outResponseBody |
65 | | - $outResponse.contentType:="text/html; charset=UTF-8" |
| 74 | + // If $responseFile is a 4D.File, we process it as a template |
| 75 | + Case of |
| 76 | + : ((Value type($responseRedirectURI)=Is text) && Length($responseRedirectURI)>0) |
| 77 | + // If we have a redirect URI, we just send a redirect to that URI |
| 78 | + $outResponse.status:=302 // Temporary redirect |
| 79 | + $outResponse.redirectURL:=String($responseRedirectURI) |
| 80 | + |
| 81 | + : (OB Instance of($responseFile; 4D.File)) |
| 82 | + If ($responseFile=Null) |
| 83 | + $responseFile:=Folder(fk resources folder).file("responseTemplate.html") |
| 84 | + End if |
| 85 | + |
| 86 | + var $responseFileContent : Text:=$responseFile.getText() |
| 87 | + var $outResponseBody : Text:="" |
| 88 | + |
| 89 | + PROCESS 4D TAGS($responseFileContent; $outResponseBody; $pageTitle; $pageMessage; $pageDetails) |
| 90 | + |
| 91 | + $outResponse.status:=200 |
| 92 | + $outResponse.body:=$outResponseBody |
| 93 | + $outResponse.contentType:="text/html; charset=UTF-8" |
| 94 | + Else |
| 95 | + |
| 96 | + // If we don't have a redirect URI or a response file, we just send a 500 Internal Server Error response |
| 97 | + $outResponse.status:=500 |
| 98 | + $outResponse.body:=cs.Tools.me.buildPageFromTemplate($pageTitle; "500 Internal Server Error"; $pageMessage) |
| 99 | + $outResponse.contentType:="text/html; charset=UTF-8" |
| 100 | + End case |
66 | 101 |
|
67 | 102 | return True |
68 | 103 |
|
|
0 commit comments