1+ using System ;
2+ using System . IO ;
3+ using System . Reflection ;
4+ using System . Threading . Tasks ;
5+ using GeneXus . Cache ;
6+ using GeneXus . Deploy . AzureFunctions . HttpHandler ;
7+ using GxClasses . Web ;
8+ using GxClasses . Web . Middleware ;
9+ using Microsoft . AspNetCore . Http ;
10+ using Microsoft . Azure . Functions . Worker ;
11+ using Microsoft . Azure . Functions . Worker . Http ;
12+ using Microsoft . Extensions . Logging ;
13+ using HttpRequestData = Microsoft . Azure . Functions . Worker . Http . HttpRequestData ;
14+
15+ namespace GeneXus . Deploy . AzureFunctions . GAM
16+ {
17+ public class GAMAzureFunctions
18+ {
19+ private IGXRouting _gxRouting ;
20+ private ICacheService2 _redis ;
21+
22+ public GAMAzureFunctions ( IGXRouting gxRouting , ICacheService2 redis )
23+ {
24+ _gxRouting = gxRouting ;
25+ if ( redis != null && redis . GetType ( ) == typeof ( Redis ) )
26+ _redis = redis ;
27+ }
28+
29+ [ Function ( "oauth_access_token" ) ]
30+ public async Task < HttpResponseData > Accesstoken ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/access_token" ) ] HttpRequestData req ,
31+ FunctionContext executionContext )
32+ {
33+ return await ExecuteHttpFunction ( req , executionContext ) ;
34+ }
35+
36+ [ Function ( "oauth_logout" ) ]
37+ public async Task < HttpResponseData > Logout ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/logout" ) ] HttpRequestData req ,
38+ FunctionContext executionContext )
39+ {
40+ return await ExecuteHttpFunction ( req , executionContext ) ;
41+ }
42+
43+ [ Function ( "oauth_userinfo" ) ]
44+ public async Task < HttpResponseData > UserInfo ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/userinfo" ) ] HttpRequestData req ,
45+ FunctionContext executionContext )
46+ {
47+ return await ExecuteHttpFunction ( req , executionContext ) ;
48+ }
49+
50+ [ Function ( "oauth_gam_signin" ) ]
51+ public async Task < HttpResponseData > Signin ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/gam/signin" ) ] HttpRequestData req ,
52+ FunctionContext executionContext )
53+ {
54+ return await ExecuteHttpFunction ( req , executionContext ) ;
55+ }
56+
57+ [ Function ( "oauth_gam_callback" ) ]
58+ public async Task < HttpResponseData > Callback ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/gam/callback" ) ] HttpRequestData req ,
59+ FunctionContext executionContext )
60+ {
61+ return await ExecuteHttpFunction ( req , executionContext ) ;
62+ }
63+
64+ [ Function ( "oauth_gam_access_token" ) ]
65+ public async Task < HttpResponseData > GAMAccessToken ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/gam/access_token" ) ] HttpRequestData req ,
66+ FunctionContext executionContext )
67+ {
68+ return await ExecuteHttpFunction ( req , executionContext ) ;
69+ }
70+
71+ [ Function ( "oauth_gam_userinfo" ) ]
72+ public async Task < HttpResponseData > GAMUserInfo ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/gam/userinfo" ) ] HttpRequestData req ,
73+ FunctionContext executionContext )
74+ {
75+ return await ExecuteHttpFunction ( req , executionContext ) ;
76+ }
77+
78+ [ Function ( "oauth_gam_signout" ) ]
79+ public async Task < HttpResponseData > GAMSignout ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/gam/signout" ) ] HttpRequestData req ,
80+ FunctionContext executionContext )
81+ {
82+ return await ExecuteHttpFunction ( req , executionContext ) ;
83+ }
84+
85+ [ Function ( "oauth_RequestTokenService" ) ]
86+ public async Task < HttpResponseData > RequestTokenService ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/RequestTokenService" ) ] HttpRequestData req ,
87+ FunctionContext executionContext )
88+ {
89+ return await ExecuteHttpFunction ( req , executionContext ) ;
90+ }
91+
92+ [ Function ( "oauth_QueryAccessToken" ) ]
93+ public async Task < HttpResponseData > QueryAccessToken ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "oauth/QueryAccessToken" ) ] HttpRequestData req ,
94+ FunctionContext executionContext )
95+ {
96+ return await ExecuteHttpFunction ( req , executionContext ) ;
97+ }
98+
99+ [ Function ( "saml_gam_signout" ) ]
100+ public async Task < HttpResponseData > SAMLGAMSignout ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "saml/gam/signout" ) ] HttpRequestData req ,
101+ FunctionContext executionContext )
102+ {
103+ return await ExecuteHttpFunction ( req , executionContext ) ;
104+ }
105+
106+ [ Function ( "saml_gam_signin" ) ]
107+ public async Task < HttpResponseData > SAMLGAMSigin ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" , Route = "saml/gam/signin" ) ] HttpRequestData req ,
108+ FunctionContext executionContext )
109+ {
110+ return await ExecuteHttpFunction ( req , executionContext ) ;
111+ }
112+
113+ private async Task < HttpResponseData > ExecuteHttpFunction ( HttpRequestData req , FunctionContext executionContext )
114+ {
115+
116+ var logger = executionContext . GetLogger ( "GAMAzureFunctions" ) ;
117+ logger . LogInformation ( $ "GeneXus Http trigger handler. Function processed: { executionContext . FunctionDefinition . Name } .") ;
118+
119+ HttpResponseData httpResponseData = req . CreateResponse ( ) ;
120+ HttpContext httpAzureContextAccessor = new GXHttpAzureContextAccessor ( req , httpResponseData , _redis ) ;
121+
122+ GXRouting . ContentRootPath = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
123+ GXRouting . AzureFunctionName = executionContext . FunctionDefinition . Name ;
124+
125+ await _gxRouting . ProcessRestRequest ( httpAzureContextAccessor ) ;
126+ return httpResponseData ;
127+ }
128+ }
129+
130+ }
0 commit comments