Confirmed users
358
edits
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
Sagrada Services are implemented as [http://docs.pylonsproject.org/en/latest/docs/pyramid.html Pyramid] web applications, using some additional libraries such as [http://github.com/mozilla-services/cornice cornice] and [http://github.com/mozilla-services/mozservices mozsvc] to make common tasks easier. | Sagrada Services are implemented as [http://docs.pylonsproject.org/en/latest/docs/pyramid.html Pyramid] web applications, using some additional libraries such as [http://github.com/mozilla-services/cornice cornice] and [http://github.com/mozilla-services/mozservices mozsvc] to make common tasks easier. | ||
== Application Structure == | == Application Structure == | ||
| Line 8: | Line 9: | ||
from mozsvc.config import get_configurator | from mozsvc.config import get_configurator | ||
def main(global_config, **settings): | def main(global_config, **settings): | ||
# Load configuration from the .ini settings file. | # Load configuration from the .ini settings file. | ||
| Line 24: | Line 25: | ||
# Pull in view definitions from the app itself. | # Pull in view definitions from the app itself. | ||
config.scan("demoapp.views") | config.scan("demoapp.views") | ||
== Consuming Authentication Tokens == | == Consuming Authentication Tokens == | ||
| Line 29: | Line 31: | ||
As described in [Services/Sagrada/TokenServer], all access to Sagrada services is authenticated using MAC Auth tokens. This section describes how to process these tokens and extract the relevant information. | As described in [Services/Sagrada/TokenServer], all access to Sagrada services is authenticated using MAC Auth tokens. This section describes how to process these tokens and extract the relevant information. | ||
=== Using mozsvc helpers === | === Using the mozsvc helpers === | ||
By including the "mozsvc.user.whoauth" package, applications are able to transparently consume Sagrada authentication tokens. To obtain the authenticated userid in your view code, simply access the "user" attribute of the request like so:: | By including the "mozsvc.user.whoauth" package, applications are able to transparently consume Sagrada authentication tokens. To obtain the authenticated userid in your view code, simply access the "user" attribute of the request like so:: | ||
| Line 40: | Line 42: | ||
return "Authenticated as " + str(uid) | return "Authenticated as " + str(uid) | ||
Behind the scenes, mozsvc configures an instance of the [http://github.com/mozilla-services/repoze.who.plugins.macauth repoze.who macauth plugin] and installs it into the pyramid authentication machinery via [http://github.com/mozilla-services/pyramid_whoauth pyramid_whoauth]. | Behind the scenes, mozsvc configures an instance of the [http://github.com/mozilla-services/repoze.who.plugins.macauth repoze.who macauth plugin] and installs it into the pyramid authentication machinery via [http://github.com/mozilla-services/pyramid_whoauth pyramid_whoauth]. The configuration file must point the plugin to the location of the [https://wiki.mozilla.org/Services/Sagrada/TokenServer#Shared_Secrets_File node secrets file]:: | ||
[who.plugin.macauth] | |||
secrets_file = /path/to/secrets/file | |||