1 USING: byte-arrays checksums.sha furnace.auth.providers
2 furnace.auth.providers.db help.markup help.syntax http kernel
3 math strings vocabs words.symbol ;
4 "furnace.auth.basic" require
5 "furnace.auth.features.deactivate-user" require
6 "furnace.auth.features.edit-profile" require
7 "furnace.auth.features.recover-password" require
8 "furnace.auth.features.registration" require
9 "furnace.auth.login" require
10 "furnace.auth.providers.assoc" require
11 "furnace.auth.providers.null" require
16 { "responder" "a responder" }
17 { "protected" "a new responder" }
19 { $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." } ;
21 HELP: >>encoded-password
22 { $values { "user" user } { "string" string } }
23 { $description "Sets the user's password by combining it with a random salt and encoding it with the current authentication realm's checksum." } ;
26 { $var-description "Global variable holding all defined capabilities. New capabilities may be defined with " { $link define-capability } "." } ;
29 { $values { "password" string } { "username" string } { "user/f" { $maybe user } } }
30 { $description "Checks a username/password pair with the current authentication realm. Outputs a user if authentication succeeded, otherwise outputs " { $link f } "." } ;
32 HELP: define-capability
33 { $values { "word" symbol } }
34 { $description "Defines a new capability by adding it to the " { $link capabilities } " global variable." } ;
38 { "string" string } { "salt" integer }
39 { "bytes" byte-array }
41 { $description "Encodes a password with the current authentication realm's checksum." } ;
43 HELP: have-capabilities?
45 { "capabilities" "a sequence of capabilities" }
48 { $description "Tests if the currently logged-in user possesses the given capabilities." } ;
51 { $var-description "Holds the currently logged-in user." } ;
55 { "description" string } { "capabilities" "a sequence of capabilities" }
57 { $description "Redirects the client to a login page." } ;
61 { "description" string } { "capabilities" "a sequence of capabilities" } { "realm" "an authenticaiton realm" }
62 { "response" response }
64 { $contract "Constructs an HTTP response for redirecting the client to a login page." } ;
67 { $class-description "The class of protected responders. See " { $link "furnace.auth.protected" } " for a description of usage and slots." } ;
70 { $class-description "The class of authentication realms. See " { $link "furnace.auth.realms" } " for details." } ;
73 { $values { "quot" { $quotation ( old -- new ) } } { "key" symbol } }
74 { $description "Applies the quotation to the old value of the user profile variable, and assigns the resulting value back to the variable." } ;
77 { $values { "key" symbol } { "value" object } }
78 { $description "Outputs the value of a user profile variable." } ;
81 { $values { "value" object } { "key" symbol } }
82 { $description "Sets the value of a user profile variable." } ;
85 { $values { "string/f" { $maybe string } }
87 { $description "Outputs the currently logged-in username, or " { $link f } " if no user is logged in." } ;
89 { $values { "provider" "an authentication provider" } }
90 { $description "Outputs the current authentication provider." } ;
92 ARTICLE: "furnace.auth.capabilities" "Authentication capabilities"
93 "Every user in the authentication framework has a set of associated capabilities."
95 "Defining new capabilities:"
96 { $subsections define-capability }
97 "Capabilities are stored in a global variable:"
98 { $subsections capabilities }
99 "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." ;
101 ARTICLE: "furnace.auth.protected" "Protected resources"
102 "To restrict access to authenticated clients only, wrap a responder in a protected responder."
107 "Protected responders have the following two slots which may be set:"
109 { { $slot "description" } "A string identifying the protected resource for user interface purposes" }
110 { { $slot "capabilities" } { "A sequence of capabilities; see " { $link "furnace.auth.capabilities" } } }
113 ARTICLE: "furnace.auth.realm-config" "Authentication realm configuration"
114 "Instances of subclasses of " { $link realm } " have the following slots which may be set:"
116 { { $slot "name" } "A string identifying the realm for user interface purposes" }
117 { { $slot "users" } { "An authentication provider (see " { $link "furnace.auth.providers" } "). By default, the " { $link users-in-db } " provider is used." } }
118 { { $slot "checksum" } { "An implementation of the checksum protocol used for verifying passwords (see " { $link "checksums" } "). The " { $link sha-256 } " checksum is used by default." } }
119 { { $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." } }
122 ARTICLE: "furnace.auth.providers" "Authentication providers"
123 "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."
125 "Each authentication realm has a provider stored in the " { $slot "users" } " slot. The default provider is " { $link users-in-db } "."
127 "furnace.auth.providers.protocol"
128 "furnace.auth.providers.null"
129 "furnace.auth.providers.assoc"
130 "furnace.auth.providers.db"
133 ARTICLE: "furnace.auth.features" "Optional authentication features"
134 "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."
136 "furnace.auth.features.deactivate-user"
137 "furnace.auth.features.edit-profile"
138 "furnace.auth.features.recover-password"
139 "furnace.auth.features.registration"
142 ARTICLE: "furnace.auth.realms" "Authentication realms"
143 "The superclass of authentication realms:"
144 { $subsections realm }
145 "There are two concrete implementations:"
150 "Authentication realms need to be configured after construction."
151 { $subsections "furnace.auth.realm-config" } ;
153 ARTICLE: "furnace.auth.users" "User profiles"
154 "A responder wrapped in an authentication realm may access the currently logged-in user,"
155 { $subsections logged-in-user }
156 "as well as the logged-in username:"
157 { $subsections username }
158 "Values can also be stored in user profile variables:"
164 "User profile variables have the same restrictions on their values as session variables; see " { $link "furnace.sessions.serialize" } " for a discussion." ;
166 ARTICLE: "furnace.auth.example" "Furnace authentication example"
167 "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”:"
170 \"view your todo list\" >>description"
172 "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:"
175 \"delete wiki articles\" >>description
176 { can-delete-wiki-articles? } >>capabilities"
178 "The " { $vocab-link "websites.concatenative" } " vocabulary wraps all of its responders, including the wiki, in a login authentication realm:"
180 ": <login-config> ( responder -- responder' )
181 \"Factor website\" <login-realm>
183 allow-password-recovery
185 allow-deactivation ;"
188 ARTICLE: "furnace.auth" "Furnace authentication"
189 "The " { $vocab-link "furnace.auth" } " vocabulary implements a pluggable authentication framework."
191 "Usernames and passwords are verified using an " { $emphasis "authentication provider" } "."
192 { $subsections "furnace.auth.providers" }
193 "Users have capabilities assigned to them."
194 { $subsections "furnace.auth.capabilities" }
195 "An " { $emphasis "authentication realm" } " is a responder which manages access to protected resources."
196 { $subsections "furnace.auth.realms" }
197 "Actions contained inside an authentication realm can be protected by wrapping them with a responder."
198 { $subsections "furnace.auth.protected" }
199 "Actions contained inside an authentication realm can access the currently logged-in user profile."
200 { $subsections "furnace.auth.users" }
201 "Authentication realms can be adorned with additional functionality."
202 { $subsections "furnace.auth.features" }
203 "A concrete example."
204 { $subsections "furnace.auth.example" } ;
206 ABOUT: "furnace.auth"