From 359ff9539e87b50ebfa1d9cde34b31c0d369385b Mon Sep 17 00:00:00 2001
From: Dries Buytaert
Distributed Authentication enables a new user to input a username and password into the login box, +
Distributed authentication enables a new user to input a username and password into the login box, and immediately be recognized, even if that user never registered at %s. This works because Drupal knows how to communicate with external registration databases. For example, lets say that new user 'Joe' is already a registered member of @@ -1608,8 +1608,8 @@ function user_help_admin() {
Registered users need to authenticate by supplying a username and password. Users may authenticate locally or via an external authentication source like Jabber, Delphi, - and other Drupal websites. See Distributed - Authentication for more information on this innovative feature. The username + and other Drupal websites. See distributed + authentication for more information on this innovative feature. The username and password are kept in your database, where the password is hashed so that no one can read nor use it. When a username and password needs to be checked the system goes down the list of registered users until it finds a matching @@ -1742,7 +1742,7 @@ function user_help_admin_da() { authentication source. Once Drupal knows that the current user is definately joe@remote.delphiforums.com (because Delphi says so), he looks up Joe's UID and logs Joe into that account.
-To disable Distributed Authentication, simply disable or remove all DA modules. For a virgin +
To disable distributed authentication, simply disable or remove all DA modules. For a virgin install, that means removing/disabling jabber.module and drupal.module
Drupal is setup so that it is very easy to add support for any external authentication
@@ -1758,13 +1758,12 @@ install, that means removing/disabling jabber.module and drupal.module
function user_help_devel_da() {
?>
- Writing Distributed Authentication Modules
+ Writing distributed authentication modules
Drupal is specifically architected to enable easy authoring of new authentication modules. I'll deconstruct the Blogger authentication module here, and hopefully provide all the details you'll need to write a new auth module. If you want to download the full text of this module, visit the - Drupal-Contrib - repository.
+ Drupal contributions CVS repository.<?php
The first line of every authentication module is the same. It is the standard @@ -1777,8 +1776,13 @@ function user_help_devel_da() { $info["link"] = "Blogger"; $info["maintainer"] = "Moshe Weitzman"; $info["maintaineremail"] = "weitzman at tejasa.com"; - if ($field) return $info[$field]; - else return $info; + + if ($field) { + return $info[$field]; + } + else { + return $info; + } }
The _info function is always the first function defined in your module. This function populates an array called $info with various pieces of @@ -1787,11 +1791,15 @@ function user_help_devel_da() { copy the blogger_info function in your module - but wherever it says blogger here, substitute your own module name.
function blogger_auth($name, $pass, $server) { - if ($server !== "blogger.com") return 0; // user did not present a Blogger ID so don't bother trying. + if ($server !== "blogger.com") { + return 0; // user did not present a Blogger ID so don't bother trying. + } + $appkey = "6D4A2D6811A6E1F75148DC1155D33C0C958107BC"; //provided to Drupal by Ev@Blogger $message = new xmlrpcmsg("blogger.getUsersBlogs", array(new xmlrpcval($appkey, "string"), new xmlrpcval($name, "string"), new xmlrpcval($pass, "string"))); $client = new xmlrpc_client("/api/RPC2", "plant.blogger.com");
$result = $client->send($message, 5); - // since Blogger doesn't return properly formed FaultCode, we just search for the string 'fault' + + // Since Blogger doesn't return a properly formed FaultCode, we just search for the string 'fault'. if ($result && !stristr($result->serialize(), "fault")) { // watchdog("user", "Success Blogger Auth. Response: " . $result->serialize()); @@ -1813,23 +1821,22 @@ function user_help_devel_da() { are passed by the user system (user.module). The user system parses the username as typed by the user into 2 substrings - $name and $server. The parsing rules are: --
- _auth function parameters
- |
+ + _auth function parameters + | ||
---|---|---|---|
$name | +$name | The substring before the final '@' character in the username field | |
$pass | +$pass | The whole string submitted by the user in the password field | |
$server | +$server | The substring after the final '@' symbol in the username field |
The lines above illustrate a typical XML-RPC +
The lines above illustrate a typical XML-RPC method call. Here we build up a message and send it to Blogger, storing the response in a variable called $response. The message we pass conforms to the published Blogger XML-RPC API. @@ -1884,17 +1891,17 @@ function user_help_devel_da() { now, just copy what you see here, substituting your module name for blogger.
function blogger_auth_help() { $site = variable_get("site_name", "this web site"); - $html_output = " - <p>You may login to <i>%s</i> using a <b>Blogger ID</b> - and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. - So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go - ahead and login now.</p>
- <p>Blogger offers you instant communication power by letting you post - your thoughts to the web whenever the urge strikes. - Blogger will publish to your current web site or help you create one. <a - href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; - - return sprintf(t($html_output), $site); + $output = " + <p>You may login to <i>%s</i> using a <b>Blogger ID</b> + and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. + So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go + ahead and login now.</p>
+ <p>Blogger offers you instant communication power by letting you post + your thoughts to the web whenever the urge strikes. + Blogger will publish to your current web site or help you create one. <a + href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; + + return sprintf(t($output), $site); }
The _auth_help function is prominently linked within Drupal, so you'll @@ -1906,8 +1913,8 @@ function user_help_devel_da() {
Once you've written and tested your authentication module, you'll have to usually
want to share it with the world. The best way to do this is to add the module
- to the Drupal-Contrib
- repository. You'll need to request priveleges in this repository - see README
+ to the Drupal
+ contributions CVS repository. You'll need to request priveleges in this repository - see README
for the details. Then you'll want to announce your contribution on the Drupal_devel
and Drupal_support mailing lists. You might also want to post a story on
Drop.org.
@@ -1918,7 +1925,7 @@ function user_help_devel_da() {
function user_help_devel_userhook() {
?>
The _user() hook provides to Module Authors a mechanism for inserting text and form fields into the registration page, the user account view/edit pages, and the administer users page. This is useful if you want to add a custom field for your particular community. This is best illustrated by an example called profile.module in the Contrib repository. Profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.
+The _user() hook provides to module authors a mechanism for inserting text and form fields into the registration page, the user account view/edit pages, and the administer users page. This is useful if you want to add a custom field for your particular community. This is best illustrated by an example called profile.module in the contributions CVS repository. Profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.
Consider this simpler example from a fictional recipe community web site called Julia's Kitchen. Julia customizes her Drupal powered site by creating a new file called julia.module. That file does the following: - new members must agree to Julia's Privacy Policy on the reg page. diff --git a/modules/user/user.module b/modules/user/user.module index 992cbc584..bfeb43343 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1054,7 +1054,7 @@ function user_page() { break; case "help": $theme->header(); - $theme->box(t("Distributed Authentication"), user_help_users_da()); + $theme->box(t("Distributed authentication"), user_help_users_da()); $theme->footer(); break; default: @@ -1557,7 +1557,7 @@ function user_help_users_da() { $output .= ". This capability is called Distributed Authentication, and is unique to Drupal, the software which powers %s.
-Distributed Authentication enables a new user to input a username and password into the login box, +
Distributed authentication enables a new user to input a username and password into the login box, and immediately be recognized, even if that user never registered at %s. This works because Drupal knows how to communicate with external registration databases. For example, lets say that new user 'Joe' is already a registered member of @@ -1608,8 +1608,8 @@ function user_help_admin() {
Registered users need to authenticate by supplying a username and password. Users may authenticate locally or via an external authentication source like Jabber, Delphi, - and other Drupal websites. See Distributed - Authentication for more information on this innovative feature. The username + and other Drupal websites. See distributed + authentication for more information on this innovative feature. The username and password are kept in your database, where the password is hashed so that no one can read nor use it. When a username and password needs to be checked the system goes down the list of registered users until it finds a matching @@ -1742,7 +1742,7 @@ function user_help_admin_da() { authentication source. Once Drupal knows that the current user is definately joe@remote.delphiforums.com (because Delphi says so), he looks up Joe's UID and logs Joe into that account.
-To disable Distributed Authentication, simply disable or remove all DA modules. For a virgin +
To disable distributed authentication, simply disable or remove all DA modules. For a virgin install, that means removing/disabling jabber.module and drupal.module
Drupal is setup so that it is very easy to add support for any external authentication
@@ -1758,13 +1758,12 @@ install, that means removing/disabling jabber.module and drupal.module
function user_help_devel_da() {
?>
- Writing Distributed Authentication Modules
+ Writing distributed authentication modules
Drupal is specifically architected to enable easy authoring of new authentication modules. I'll deconstruct the Blogger authentication module here, and hopefully provide all the details you'll need to write a new auth module. If you want to download the full text of this module, visit the - Drupal-Contrib - repository.
+ Drupal contributions CVS repository.<?php
The first line of every authentication module is the same. It is the standard @@ -1777,8 +1776,13 @@ function user_help_devel_da() { $info["link"] = "Blogger"; $info["maintainer"] = "Moshe Weitzman"; $info["maintaineremail"] = "weitzman at tejasa.com"; - if ($field) return $info[$field]; - else return $info; + + if ($field) { + return $info[$field]; + } + else { + return $info; + } }
The _info function is always the first function defined in your module. This function populates an array called $info with various pieces of @@ -1787,11 +1791,15 @@ function user_help_devel_da() { copy the blogger_info function in your module - but wherever it says blogger here, substitute your own module name.
function blogger_auth($name, $pass, $server) { - if ($server !== "blogger.com") return 0; // user did not present a Blogger ID so don't bother trying. + if ($server !== "blogger.com") { + return 0; // user did not present a Blogger ID so don't bother trying. + } + $appkey = "6D4A2D6811A6E1F75148DC1155D33C0C958107BC"; //provided to Drupal by Ev@Blogger $message = new xmlrpcmsg("blogger.getUsersBlogs", array(new xmlrpcval($appkey, "string"), new xmlrpcval($name, "string"), new xmlrpcval($pass, "string"))); $client = new xmlrpc_client("/api/RPC2", "plant.blogger.com");
$result = $client->send($message, 5); - // since Blogger doesn't return properly formed FaultCode, we just search for the string 'fault' + + // Since Blogger doesn't return a properly formed FaultCode, we just search for the string 'fault'. if ($result && !stristr($result->serialize(), "fault")) { // watchdog("user", "Success Blogger Auth. Response: " . $result->serialize()); @@ -1813,23 +1821,22 @@ function user_help_devel_da() { are passed by the user system (user.module). The user system parses the username as typed by the user into 2 substrings - $name and $server. The parsing rules are: --
- _auth function parameters
- |
+ + _auth function parameters + | ||
---|---|---|---|
$name | +$name | The substring before the final '@' character in the username field | |
$pass | +$pass | The whole string submitted by the user in the password field | |
$server | +$server | The substring after the final '@' symbol in the username field |
The lines above illustrate a typical XML-RPC +
The lines above illustrate a typical XML-RPC method call. Here we build up a message and send it to Blogger, storing the response in a variable called $response. The message we pass conforms to the published Blogger XML-RPC API. @@ -1884,17 +1891,17 @@ function user_help_devel_da() { now, just copy what you see here, substituting your module name for blogger.
function blogger_auth_help() { $site = variable_get("site_name", "this web site"); - $html_output = " - <p>You may login to <i>%s</i> using a <b>Blogger ID</b> - and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. - So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go - ahead and login now.</p>
- <p>Blogger offers you instant communication power by letting you post - your thoughts to the web whenever the urge strikes. - Blogger will publish to your current web site or help you create one. <a - href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; - - return sprintf(t($html_output), $site); + $output = " + <p>You may login to <i>%s</i> using a <b>Blogger ID</b> + and password. A Blogger ID consists of your Blogger username followed by <i>@blogger.com</i>. + So a valid blogger ID is mwlily@blogger.com. If you are a Blogger member, go + ahead and login now.</p>
+ <p>Blogger offers you instant communication power by letting you post + your thoughts to the web whenever the urge strikes. + Blogger will publish to your current web site or help you create one. <a + href=\"http://www.blogger.com/about.pyra\">Learn more about it</a>."; + + return sprintf(t($output), $site); }
The _auth_help function is prominently linked within Drupal, so you'll @@ -1906,8 +1913,8 @@ function user_help_devel_da() {
Once you've written and tested your authentication module, you'll have to usually
want to share it with the world. The best way to do this is to add the module
- to the Drupal-Contrib
- repository. You'll need to request priveleges in this repository - see README
+ to the Drupal
+ contributions CVS repository. You'll need to request priveleges in this repository - see README
for the details. Then you'll want to announce your contribution on the Drupal_devel
and Drupal_support mailing lists. You might also want to post a story on
Drop.org.
@@ -1918,7 +1925,7 @@ function user_help_devel_da() {
function user_help_devel_userhook() {
?>
The _user() hook provides to Module Authors a mechanism for inserting text and form fields into the registration page, the user account view/edit pages, and the administer users page. This is useful if you want to add a custom field for your particular community. This is best illustrated by an example called profile.module in the Contrib repository. Profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.
+The _user() hook provides to module authors a mechanism for inserting text and form fields into the registration page, the user account view/edit pages, and the administer users page. This is useful if you want to add a custom field for your particular community. This is best illustrated by an example called profile.module in the contributions CVS repository. Profile.module is meant to be customized for your needs. Please download it and hack away until it does what you need.
Consider this simpler example from a fictional recipe community web site called Julia's Kitchen. Julia customizes her Drupal powered site by creating a new file called julia.module. That file does the following: - new members must agree to Julia's Privacy Policy on the reg page. -- cgit v1.2.3