gustafn
committed
on 21 Nov 08
-update to version 0.100, compliant with xowiki 0.105
openacs-4/.../xooauth/tcl/rest-procs.tcl (+32 -10)
18 18
19 19         #
20 20         # The client_id/client_secret identifies the registered "app"
21 21         # for which later app-tokens are used to issue action via the
22 22         # REST interface.
23 23         #
24 24         :property {client_id}
25 25         :property {client_secret}
26 26
27 27         :method init {} {
28 28             #
29 29             # Make sure, we have the nsv array for application tokens
30 30             # defined.
31 31             #
32 32             nsv_set -default app_token [self] ""
33 33
34 34             #
35 35             # Set defaults for instance variables from the
36 36             # configuration file. This lookup is fairly generic and
37 37             # takes into account the configure parameter of subclasses
38               # of xo::REST. The parameters are looked up on a path
39               # consisting of the namespace of the defining class and
40               # the instance name. So, for the Microsoft Graph and Azure
41               # interface defined as
  38             # of xo::REST. The parameters are looked up from the
  39             # configuration file on a path consisting of the namespace
  40             # of the defining class and the instance name. So, one
  41             # cloud define an app (an MS administrative agent)
  42             # "ms::app" for the Microsoft Graph and Azure and
  43             # interface objects for the oauth identity providers
  44             # "ms::azure" and "xo::oauth::github" like:
42 45             #
43               #     ::ms::Graph create app
44               #     ::ms::Authorize create azure
  46             #     ::ms::Graph create ::ms::app
  47             #     ::ms::Authorize create ::ms::azure
  48             #     ::xo::oauth::GitHub create ::xo::oauth::github
45 49             #
46               # The lookup will be attempted at least for the
47               # "client_id" and "client_secret".
  50             # The parameters for these objects can be specified during
  51             # creation (.... -client:id "..." ...) or in the
  52             # configuration file in the following sections:
48 53             #
  54             #     ns/server/[ns_info server]/acs/oauth/ms/app
  55             #     ns/server/[ns_info server]/acs/oauth/ms/azure
  56             #     ns/server/[ns_info server]/acs/oauth/github
  57             #
  58             # In case, one wants a common parameters for "ms::app" and
  59             # "ms::azure", one might use just the section:
  60             #
  61             #     ns/server/[ns_info server]/acs/oauth/ms
  62             #
  63            
49 64             set clientName [namespace tail [self]]
50 65             set namespace [string trimleft [namespace parent [:info class]] :]
  66             if {$namespace eq "xo::oauth"} {
  67                 set namespace ""
  68             }
51 69             #
52 70             # First lookup on the level of the app, then on the level
53 71             # above this (e.g. first ".../ms/app", ".../ms/azure",
54 72             # then ".../ms". When both are used and use the e.g. the
55 73             # identical "client_id", use the section ".../ms".
56 74             #
57               set sections "ns/server/[ns_info server]/$namespace/$clientName"
58               lappend sections "ns/server/[ns_info server]/$namespace"
  75             if {$namespace ne ""} {
  76                 set sections "ns/server/[ns_info server]/acs/oauth/$namespace/$clientName"
  77                 lappend sections "ns/server/[ns_info server]/acs/oauth/$namespace"
  78             } else {
  79                 set sections "ns/server/[ns_info server]/acs/oauth/$clientName"
  80             }
59 81             set configureParameters [lmap p [:info lookup variables] {
60 82                 namespace tail $p
61 83             }]
62 84             ns_log notice "[self] configure parameters: $configureParameters"
63 85
64 86             foreach section $sections {
65 87                 foreach param $configureParameters {
66 88                     if {![info exists :$param]} {
67 89                         set value [ns_config $section $param]
68 90                         #ns_log notice "[self] '$section' '$param' -> '$value'"
69 91                         if {$value ne ""} {
70 92                             ns_log notice "[self] config $param -> '$value'"
71 93                             set :$param $value
72 94                         }
73 95                     }
74 96                 }
75 97             }
76 98             next
77 99         }
78 100