]> gitweb.factorcode.org Git - factor.git/blob - basis/furnace/auth/auth-docs.factor
docs: change ``{ $quotation "( x -- y )" }`` to ``{ $quotation ( x -- y ) }``.
[factor.git] / basis / furnace / auth / auth-docs.factor
1 USING: assocs classes help.markup help.syntax kernel
2 quotations strings words words.symbol furnace.auth.providers.db
3 checksums.sha furnace.auth.providers math byte-arrays
4 http ;
5 IN: furnace.auth
6
7 HELP: <protected>
8 { $values
9      { "responder" "a responder" }
10      { "protected" "a new responder" }
11 }
12 { $description "Wraps a responder in a protected responder. Access to the wrapped responder will be conditional upon the client authenticating with the current authentication realm." } ;
13
14 HELP: >>encoded-password
15 { $values { "user" user } { "string" string } }
16 { $description "Sets the user's password by combining it with a random salt and encoding it with the current authentication realm's checksum." } ;
17
18 HELP: capabilities
19 { $var-description "Global variable holding all defined capabilities. New capabilities may be defined with " { $link define-capability } "." } ;
20
21 HELP: check-login
22 { $values { "password" string } { "username" string } { "user/f" { $maybe user } } }
23 { $description "Checks a username/password pair with the current authentication realm. Outputs a user if authentication succeeded, otherwise outputs " { $link f } "." } ;
24
25 HELP: define-capability
26 { $values { "word" symbol } }
27 { $description "Defines a new capability by adding it to the " { $link capabilities } " global variable." } ;
28
29 HELP: encode-password
30 { $values
31      { "string" string } { "salt" integer }
32      { "bytes" byte-array }
33 }
34 { $description "Encodes a password with the current authentication realm's checksum." } ;
35
36 HELP: have-capabilities?
37 { $values
38      { "capabilities" "a sequence of capabilities" }
39      { "?" "a boolean" }
40 }
41 { $description "Tests if the currently logged-in user possesses the given capabilities." } ;
42
43 HELP: logged-in-user
44 { $var-description "Holds the currently logged-in user." } ;
45
46 HELP: login-required
47 { $values
48      { "description" string } { "capabilities" "a sequence of capabilities" }
49 }
50 { $description "Redirects the client to a login page." } ;
51
52 HELP: login-required*
53 { $values
54      { "description" string } { "capabilities" "a sequence of capabilities" } { "realm" "an authenticaiton realm" }
55      { "response" response }
56 }
57 { $contract "Constructs an HTTP response for redirecting the client to a login page." } ;
58
59 HELP: protected
60 { $class-description "The class of protected responders. See " { $link "furnace.auth.protected" } " for a description of usage and slots." } ;
61
62 HELP: realm
63 { $class-description "The class of authentication realms. See " { $link "furnace.auth.realms" } " for details." } ;
64
65 HELP: uchange
66 { $values { "quot" { $quotation ( old -- new ) } } { "key" symbol } }
67 { $description "Applies the quotation to the old value of the user profile variable, and assigns the resulting value back to the variable." } ;
68
69 HELP: uget
70 { $values { "key" symbol } { "value" object } }
71 { $description "Outputs the value of a user profile variable." } ;
72
73 HELP: uset
74 { $values { "value" object } { "key" symbol } }
75 { $description "Sets the value of a user profile variable." } ;
76
77 HELP: username
78 { $values { "string/f" { $maybe string } }
79 }
80 { $description "Outputs the currently logged-in username, or " { $link f } " if no user is logged in." } ;
81 HELP: users
82 { $values { "provider" "an authentication provider" } }
83 { $description "Outputs the current authentication provider." } ;
84
85 ARTICLE: "furnace.auth.capabilities" "Authentication capabilities"
86 "Every user in the authentication framework has a set of associated capabilities."
87 $nl
88 "Defining new capabilities:"
89 { $subsections define-capability }
90 "Capabilities are stored in a global variable:"
91 { $subsections capabilities }
92 "Protected resources can be restricted to users possessing certain capabilities only by storing a sequence of capabilities in the " { $slot "capabilities" } " slot of a " { $link protected } " instance." ;
93
94 ARTICLE: "furnace.auth.protected" "Protected resources"
95 "To restrict access to authenticated clients only, wrap a responder in a protected responder."
96 { $subsections
97     protected
98     <protected>
99 }
100 "Protected responders have the following two slots which may be set:"
101 { $table
102     { { $slot "description" } "A string identifying the protected resource for user interface purposes" }
103     { { $slot "capabilities" } { "A sequence of capabilities; see " { $link "furnace.auth.capabilities" } } }
104 } ;
105
106 ARTICLE: "furnace.auth.realm-config" "Authentication realm configuration"
107 "Instances of subclasses of " { $link realm } " have the following slots which may be set:"
108 { $table
109     { { $slot "name" } "A string identifying the realm for user interface purposes" }
110     { { $slot "users" } { "An authentication provider (see " { $link "furnace.auth.providers" } "). By default, the " { $link users-in-db } " provider is used." } }
111     { { $slot "checksum" } { "An implementation of the checksum protocol used for verifying passwords (see " { $link "checksums" } "). The " { $link sha-256 } " checksum is used by default." } }
112     { { $slot "secure" } { "A boolean, that when set to a true value, forces the client to access the authentication realm via HTTPS. An attempt to access the realm via HTTP results in a redirect to the corresponding HTTPS URL. On by default." } }
113 } ;
114
115 ARTICLE: "furnace.auth.providers" "Authentication providers"
116 "The " { $vocab-link "furnace.auth" } " framework looks up users using an authentication provider. Different authentication providers can be swapped in to implement various authentication strategies."
117 $nl
118 "Each authentication realm has a provider stored in the " { $slot "users" } " slot. The default provider is " { $link users-in-db } "."
119 { $subsections
120     "furnace.auth.providers.protocol"
121     "furnace.auth.providers.null"
122     "furnace.auth.providers.assoc"
123     "furnace.auth.providers.db"
124     "furnace.auth.providers.couchdb"
125 } ;
126
127 ARTICLE: "furnace.auth.features" "Optional authentication features"
128 "Vocabularies having names prefixed by " { $code "furnace.auth.features" } " implement optional features which can be enabled by calling special words. These words define new actions on an authentication realm."
129 { $subsections
130     "furnace.auth.features.deactivate-user"
131     "furnace.auth.features.edit-profile"
132     "furnace.auth.features.recover-password"
133     "furnace.auth.features.registration"
134 } ;
135
136 ARTICLE: "furnace.auth.realms" "Authentication realms"
137 "The superclass of authentication realms:"
138 { $subsections realm }
139 "There are two concrete implementations:"
140 { $subsections
141     "furnace.auth.basic"
142     "furnace.auth.login"
143 }
144 "Authentication realms need to be configured after construction."
145 { $subsections "furnace.auth.realm-config" } ;
146
147 ARTICLE: "furnace.auth.users" "User profiles"
148 "A responder wrapped in an authentication realm may access the currently logged-in user,"
149 { $subsections logged-in-user }
150 "as well as the logged-in username:"
151 { $subsections username }
152 "Values can also be stored in user profile variables:"
153 { $subsections
154     uget
155     uset
156     uchange
157 }
158 "User profile variables have the same restrictions on their values as session variables; see " { $link "furnace.sessions.serialize" } " for a discussion." ;
159
160 ARTICLE: "furnace.auth.example" "Furnace authentication example"
161 "The " { $vocab-link "webapps.todo" } " vocabulary wraps all of its responders in a protected responder. The " { $slot "description" } " slot is set so that the login page contains the message “You must log in to view your todo list”:"
162 { $code
163     """<protected>
164     "view your todo list" >>description"""
165 }
166 "The " { $vocab-link "webapps.wiki" } " vocabulary defines a mix of protected and unprotected actions. One example of a protected action is that for deleting wiki pages, an action normally reserved for administrators. This action is protected with the following code:"
167 { $code
168     """<protected>
169     "delete wiki articles" >>description
170     { can-delete-wiki-articles? } >>capabilities"""
171 }
172 "The " { $vocab-link "websites.concatenative" } " vocabulary wraps all of its responders, including the wiki, in a login authentication realm:"
173 { $code
174 """: <login-config> ( responder -- responder' )
175     "Factor website" <login-realm>
176         "Factor website" >>name
177         allow-registration
178         allow-password-recovery
179         allow-edit-profile
180         allow-deactivation ;"""
181 } ;
182
183 ARTICLE: "furnace.auth" "Furnace authentication"
184 "The " { $vocab-link "furnace.auth" } " vocabulary implements a pluggable authentication framework."
185 $nl
186 "Usernames and passwords are verified using an " { $emphasis "authentication provider" } "."
187 { $subsections "furnace.auth.providers" }
188 "Users have capabilities assigned to them."
189 { $subsections "furnace.auth.capabilities" }
190 "An " { $emphasis "authentication realm" } " is a responder which manages access to protected resources."
191 { $subsections "furnace.auth.realms" }
192 "Actions contained inside an authentication realm can be protected by wrapping them with a responder."
193 { $subsections "furnace.auth.protected" }
194 "Actions contained inside an authentication realm can access the currently logged-in user profile."
195 { $subsections "furnace.auth.users" }
196 "Authentication realms can be adorned with additional functionality."
197 { $subsections "furnace.auth.features" }
198 "An administration tool."
199 { $subsections "webapps.user-admin" }
200 "A concrete example."
201 { $subsections "furnace.auth.example" } ;
202
203 ABOUT: "furnace.auth"