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
9 { "responder" "a responder" }
10 { "protected" "a new responder" }
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." } ;
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." } ;
19 { $var-description "Global variable holding all defined capabilities. New capabilities may be defined with " { $link define-capability } "." } ;
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 } "." } ;
25 HELP: define-capability
26 { $values { "word" symbol } }
27 { $description "Defines a new capability by adding it to the " { $link capabilities } " global variable." } ;
31 { "string" string } { "salt" integer }
32 { "bytes" byte-array }
34 { $description "Encodes a password with the current authentication realm's checksum." } ;
36 HELP: have-capabilities?
38 { "capabilities" "a sequence of capabilities" }
41 { $description "Tests if the currently logged-in user possesses the given capabilities." } ;
44 { $var-description "Holds the currently logged-in user." } ;
48 { "description" string } { "capabilities" "a sequence of capabilities" }
50 { $description "Redirects the client to a login page." } ;
54 { "description" string } { "capabilities" "a sequence of capabilities" } { "realm" "an authenticaiton realm" }
55 { "response" response }
57 { $contract "Constructs an HTTP response for redirecting the client to a login page." } ;
60 { $class-description "The class of protected responders. See " { $link "furnace.auth.protected" } " for a description of usage and slots." } ;
63 { $class-description "The class of authentication realms. See " { $link "furnace.auth.realms" } " for details." } ;
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." } ;
70 { $values { "key" symbol } { "value" object } }
71 { $description "Outputs the value of a user profile variable." } ;
74 { $values { "value" object } { "key" symbol } }
75 { $description "Sets the value of a user profile variable." } ;
78 { $values { "string/f" { $maybe string } }
80 { $description "Outputs the currently logged-in username, or " { $link f } " if no user is logged in." } ;
82 { $values { "provider" "an authentication provider" } }
83 { $description "Outputs the current authentication provider." } ;
85 ARTICLE: "furnace.auth.capabilities" "Authentication capabilities"
86 "Every user in the authentication framework has a set of associated capabilities."
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." ;
94 ARTICLE: "furnace.auth.protected" "Protected resources"
95 "To restrict access to authenticated clients only, wrap a responder in a protected responder."
100 "Protected responders have the following two slots which may be set:"
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" } } }
106 ARTICLE: "furnace.auth.realm-config" "Authentication realm configuration"
107 "Instances of subclasses of " { $link realm } " have the following slots which may be set:"
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." } }
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."
118 "Each authentication realm has a provider stored in the " { $slot "users" } " slot. The default provider is " { $link users-in-db } "."
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"
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."
130 "furnace.auth.features.deactivate-user"
131 "furnace.auth.features.edit-profile"
132 "furnace.auth.features.recover-password"
133 "furnace.auth.features.registration"
136 ARTICLE: "furnace.auth.realms" "Authentication realms"
137 "The superclass of authentication realms:"
138 { $subsections realm }
139 "There are two concrete implementations:"
144 "Authentication realms need to be configured after construction."
145 { $subsections "furnace.auth.realm-config" } ;
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:"
158 "User profile variables have the same restrictions on their values as session variables; see " { $link "furnace.sessions.serialize" } " for a discussion." ;
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”:"
164 "view your todo list" >>description"""
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:"
169 "delete wiki articles" >>description
170 { can-delete-wiki-articles? } >>capabilities"""
172 "The " { $vocab-link "websites.concatenative" } " vocabulary wraps all of its responders, including the wiki, in a login authentication realm:"
174 """: <login-config> ( responder -- responder' )
175 "Factor website" <login-realm>
176 "Factor website" >>name
178 allow-password-recovery
180 allow-deactivation ;"""
183 ARTICLE: "furnace.auth" "Furnace authentication"
184 "The " { $vocab-link "furnace.auth" } " vocabulary implements a pluggable authentication framework."
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" } ;
203 ABOUT: "furnace.auth"