Confirmed users
358
edits
Line 21: | Line 21: | ||
# Use standard authentication modules | # Use standard authentication modules | ||
config.include("mozsvc.user | config.include("mozsvc.user") | ||
# Pull in view definitions from the app itself. | # Pull in view definitions from the app itself. | ||
Line 35: | Line 35: | ||
=== Using the mozsvc helpers === | === Using the mozsvc helpers === | ||
By including the "mozsvc.user | By including the "mozsvc.user" 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: | ||
def some_view(request): | def some_view(request): | ||
Line 46: | Line 46: | ||
Requests with a valid authentication header will have request.user as a dict containing the userid and other metadata, while requests without an authentication header will have request.user as an empty dict. If the request has an ''invalid'' authentication header then accesing request.user will result in a 401 response being returned to the client. | Requests with a valid authentication header will have request.user as a dict containing the userid and other metadata, while requests without an authentication header will have request.user as an empty dict. If the request has an ''invalid'' authentication header then accesing request.user will result in a 401 response being returned to the client. | ||
Behind the scenes, mozsvc configures an instance of the [http://github.com/mozilla-services/ | Behind the scenes, mozsvc configures an instance of the [http://github.com/mozilla-services/pyramid_macauth pyramid macauth plugin] and installs it into the pyramid authentication machinery. The deployment configuration file must point to the location of the [https://wiki.mozilla.org/Services/Sagrada/TokenServer#Shared_Secrets_File node secrets file]: | ||
[ | [macauth] | ||
secrets_file = /path/to/secrets/file | secrets_file = /path/to/secrets/file | ||