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