-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREST.OAuthZPM.cls
58 lines (47 loc) · 1.29 KB
/
REST.OAuthZPM.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Class REST.OAuthZPM Extends %CSP.REST
{
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/auth" Method="GET" Call="auth" />
<Route Url="/check" Method="GET" Call="check" />
</Routes>
}
Parameter APPLICATION = "azpm";
Parameter REDIRECTURI = "https://pm.community.intersystems.com/zpmoauth/auth";
Parameter AUTHAPPURL = "https://pm.community.intersystems.com/zpm/tableau.csp";
parameter SCOPE = "openid profile email";
Parameter UseSession = 1;
ClassMethod auth()
{
set isAuthorized = ##class(%SYS.OAuth2.AccessToken).IsAuthorized(
..#APPLICATION,
.sessionId,
..#SCOPE,
.accessToken,
.idtoken,
.responseProperties,
.error)
if isAuthorized {
set success = $SYSTEM.Security.Login(.accessToken)
&html<<script type="text/javascript"> window.location="#(..#AUTHAPPURL)#" </script>>
return $$$OK
}
set url = ##class(%SYS.OAuth2.Authorization).GetAuthorizationCodeEndpoint(
..#APPLICATION,
..#SCOPE,
..#REDIRECTURI,
.properties,
.isAuthorized,
.sc)
if $$$ISERR(sc) return sc
//&html<<a href="#(url)#">Link</a>>
&html<<script type="text/javascript"> window.location="#(url)#" </script>>
return $$$OK
}
ClassMethod check()
{
w {"url": "/zpm/zpmoauth/auth"}.%ToJSON()
return $$$OK
}
}