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 ;
8 { "responder" "a responder" }
9 { "protected" "a new responder" }
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." } ;
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." } ;
18 { $var-description "Global variable holding all defined capabilities. New capabilities may be defined with " { $link define-capability } "." } ;
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 } "." } ;
24 HELP: define-capability
25 { $values { "word" symbol } }
26 { $description "Defines a new capability by adding it to the " { $link capabilities } " global variable." } ;
30 { "string" string } { "salt" integer }
31 { "bytes" byte-array }
33 { $description "Encodes a password with the current authentication realm's checksum." } ;
35 HELP: have-capabilities?
37 { "capabilities" "a sequence of capabilities" }
40 { $description "Tests if the currently logged-in user possesses the given capabilities." } ;
43 { $var-description "Holds the currently logged-in user." } ;
47 { "description" string } { "capabilities" "a sequence of capabilities" }
49 { $description "Redirects the client to a login page." } ;
53 { "description" string } { "capabilities" "a sequence of capabilities" } { "realm" "an authenticaiton realm" }
54 { "response" response }
56 { $contract "Constructs an HTTP response for redirecting the client to a login page." } ;
59 { $class-description "The class of protected responders. See " { $link "furnace.auth.protected" } " for a description of usage and slots." } ;
62 { $class-description "The class of authentication realms. See " { $link "furnace.auth.realms" } " for details." } ;
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." } ;
69 { $values { "key" symbol } { "value" object } }
70 { $description "Outputs the value of a user profile variable." } ;
73 { $values { "value" object } { "key" symbol } }
74 { $description "Sets the value of a user profile variable." } ;
77 { $values { "string/f" { $maybe string } }
79 { $description "Outputs the currently logged-in username, or " { $link f } " if no user is logged in." } ;
81 { $values { "provider" "an authentication provider" } }
82 { $description "Outputs the current authentication provider." } ;
84 ARTICLE: "furnace.auth.capabilities" "Authentication capabilities"
85 "Every user in the authentication framework has a set of associated capabilities."
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." ;
93 ARTICLE: "furnace.auth.protected" "Protected resources"
94 "To restrict access to authenticated clients only, wrap a responder in a protected responder."
99 "Protected responders have the following two slots which may be set:"
101 { { $slot "description" } "A string identifying the protected resource for user interface purposes" }
102 { { $slot "capabilities" } { "A sequence of capabilities; see " { $link "furnace.auth.capabilities" } } }
105 ARTICLE: "furnace.auth.realm-config" "Authentication realm configuration"
106 "Instances of subclasses of " { $link realm } " have the following slots which may be set:"
108 { { $slot "name" } "A string identifying the realm for user interface purposes" }
109 { { $slot "users" } { "An authentication provider (see " { $link "furnace.auth.providers" } "). By default, the " { $link users-in-db } " provider is used." } }
110 { { $slot "checksum" } { "An implementation of the checksum protocol used for verifying passwords (see " { $link "checksums" } "). The " { $link sha-256 } " checksum is used by default." } }
111 { { $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." } }
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."
117 "Each authentication realm has a provider stored in the " { $slot "users" } " slot. The default provider is " { $link users-in-db } "."
119 "furnace.auth.providers.protocol"
120 "furnace.auth.providers.null"
121 "furnace.auth.providers.assoc"
122 "furnace.auth.providers.db"
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."
128 "furnace.auth.features.deactivate-user"
129 "furnace.auth.features.edit-profile"
130 "furnace.auth.features.recover-password"
131 "furnace.auth.features.registration"
134 ARTICLE: "furnace.auth.realms" "Authentication realms"
135 "The superclass of authentication realms:"
136 { $subsections realm }
137 "There are two concrete implementations:"
142 "Authentication realms need to be configured after construction."
143 { $subsections "furnace.auth.realm-config" } ;
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:"
156 "User profile variables have the same restrictions on their values as session variables; see " { $link "furnace.sessions.serialize" } " for a discussion." ;
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”:"
162 \"view your todo list\" >>description"
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:"
167 \"delete wiki articles\" >>description
168 { can-delete-wiki-articles? } >>capabilities"
170 "The " { $vocab-link "websites.concatenative" } " vocabulary wraps all of its responders, including the wiki, in a login authentication realm:"
172 ": <login-config> ( responder -- responder' )
173 \"Factor website\" <login-realm>
175 allow-password-recovery
177 allow-deactivation ;"
180 ARTICLE: "furnace.auth" "Furnace authentication"
181 "The " { $vocab-link "furnace.auth" } " vocabulary implements a pluggable authentication framework."
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" } ;
198 ABOUT: "furnace.auth"