x-example-authtoken is set; the value of the cookie is an auth token, such as auth:1234-5678-9abcd.
x-example-authtoken cookie is a domain level cookie, the browser will send that cookie to all requests on that site.
x-example-authtoken and, if present, will pass its value to an SSO API on example.com for verification.
https://example.com/api/auth/<authtoken>, where <authtoken> is replaced by the cookie value.
x-example-key: abcd-ef01-2345-6789
{"type":"named", "displayName":"Jimmy Neutron", "loginName":"jimmy@example.com"}
jimmy@example.com, you are guest
jimmy_40example_2ecom, this is built from the login name
Jimmyexamplecom or JimmyNeutron, you are TWikiGuest
jimmy@example.com becomes Jimmyexamplecom, and user signatures point to Main.Jimmyexamplecom.
JimmyNeutron. The mapping from login name to WikiName is done in the TWikiUsers page - fix entries there in case login names change.
lib/LocalSite.cfg configure file directly. Settings:
# ---+ Security setup section
# ---++ Authentication
# enable SSO login:
$TWiki::cfg{LoginManager} = 'TWiki::LoginManager::SsoLogin';
# remove the "@" character from the login name filter in case users login with an e-mail address:
$TWiki::cfg{LoginNameFilterIn} = '^[^\\s\\*?~^\\$%`"\'&;|<>\\x00-\\x1f]+$';
# ---++ Registration
# allow login name, and don't ask for password in registration page:
$TWiki::cfg{Register}{AllowLoginName} = 1;
# ---++ Passwords
# no password manager:
$TWiki::cfg{PasswordManager} = 'none';
# ---+ Extensions section
# name of auth token cookie:
$TWiki::cfg{SsoLoginContrib}{AuthTokenName} = 'x-authtoken-cookie-name';
# URL of SSO API to verify an auth token; %AUTHTOKEN% is set to the cookie value of the auth token
$TWiki::cfg{SsoLoginContrib}{VerifyAuthTokenUrl} = 'https://example.com/api/auth/%AUTHTOKEN%';
# Some SSO APIs require to pass a key in the header of the http request; use comma-space delimited list:
$TWiki::cfg{SsoLoginContrib}{VerifyAuthTokenHeader} = 'x-sso-api-key, API key value';
# regular expression to extract the login name from the JSON response:
$TWiki::cfg{SsoLoginContrib}{VerifyResponseLoginRE} = '"loginName":"([^"]*)';
# login URL; %ORIGURL% is set to the original URL where the user is sent after login:
$TWiki::cfg{SsoLoginContrib}{LoginUrl} = 'https://example.com/login?redirect=%ORIGURL%';
# logout URL; %ORIGURL% is set to the original URL where the user is sent after logout:
$TWiki::cfg{SsoLoginContrib}{LogoutUrl} = 'https://example.com/logout?redirect=%ORIGURL%';
If you use TWiki-5.1.1 and earlier you need to patch two TWiki modules: lib/TWiki/Users/TWikiUserMapping.pm - patch required to show a proper WikiName for unregistered users
lib/TWiki/Net.pm - patch is only needed if a custom header is required to verify an auth token with the SSO API service
lib/TWiki/Users/TWikiUserMapping.pm:
--- lib/TWiki/Users/TWikiUserMapping.pm.save1 2012-04-02 16:19:48.414434038 +0000
+++ lib/TWiki/Users/TWikiUserMapping.pm 2012-06-28 00:21:05.202658103 +0000
@@ -452,6 +452,7 @@
if ($wikiname) {
# sanitise the generated WikiName
$wikiname =~ s/$TWiki::cfg{NameFilter}//go;
+ $wikiname =~ s/\.//go;
}
}
patch for lib/TWiki/Net.pm:
--- lib/TWiki/Net.pm.save1 2012-04-02 16:19:46.360395747 +0000
+++ lib/TWiki/Net.pm 2012-06-23 05:02:03.952195847 +0000
@@ -104,16 +107,17 @@
<verbatim>
my $response = TWiki::Func::getExternalResource($url);
if (!$response->is_error() && $response->isa('HTTP::Response')) {
- ... other methods of HTTP::Response may be called
+ $text = $response->content();
+ # ... other methods of HTTP::Response may be called
} else {
- ... only the methods listed above may be called
+ # ... only the methods listed above may be called
}
</verbatim>
=cut
sub getExternalResource {
- my ($this, $url) = @_;
+ my ( $this, $url, @headers ) = @_;
my $protocol;
if( $url =~ m!^([a-z]+):! ) {
@@ -125,7 +129,7 @@
eval "use LWP";
unless( $@ ) {
- return _GETUsingLWP( $this, $url );
+ return _GETUsingLWP( $this, $url, @headers );
}
# Fallback mechanism
@@ -195,6 +199,12 @@
my $revstr=$1;
$req .= 'User-Agent: TWiki::Net/'.$revstr."\r\n";
+ if( @headers ) {
+ while( my $key = shift @headers ) {
+ my $val = shift( @headers );
+ $req .= "$key: $val\r\n" if( defined $val );
+ }
+ }
$req .= "\r\n\r\n";
my ( $iaddr, $paddr, $proto );
@@ -238,7 +248,7 @@
# =======================================
sub _GETUsingLWP {
- my( $this, $url ) = @_;
+ my( $this, $url, @headers ) = @_;
my ( $user, $pass );
if( $url =~ s!([^/\@:]+)(?::([^/\@:]+))?@!! ) {
@@ -254,7 +264,9 @@
'$Rev: 22570 (2012-01-14) $'=~/([0-9]+)/;
my $revstr=$1;
- $request->header( 'User-Agent' => 'TWiki::Net/'.$revstr." libwww-perl/$LWP::VERSION" );
+ my @allHeaders = ( 'User-Agent' => 'TWiki::Net/'.$revstr." libwww-perl/$LWP::VERSION" );
+ push( @allHeaders, @headers ) if( @headers );
+ $request->header( @allHeaders );
require TWiki::Net::UserCredAgent;
my $ua = new TWiki::Net::UserCredAgent( $user, $pass, $url );
my $response = $ua->request( $request );
SsoLoginContrib.zip in your twiki installation directory. Content: | File: | Description: |
|---|---|
data/TWiki/SsoLoginContrib.txt | Documentation topic |
lib/TWiki/Contrib/SsoLoginContrib.pm | Contrib Perl module |
lib/TWiki/Contrib/SsoLoginContrib/Config.spec | Configure spec file |
lib/TWiki/LoginManager/SsoLogin.pm | SSO Perl module |
{SsoLoginContrib}{...) settings in the Extensions section as described above.
| Author: | TWiki:Main.PeterThoeny |
| Copyright: | © 2012 Wave Systems Corp. © 2012-2013 TWiki:TWiki.TWikiContributor |
| License: | GPL (GNU General Public License |
| Dependencies: | CPAN:LWP |
| Version: | 2013-09-26 |
| Change History: | |
| 2013-09-26: | TWikibug:Item7353 |
| 2012-06-28: | TWikibug:Item6895 |
| Home: | http://TWiki.org/cgi-bin/view/Plugins/SsoLoginContrib |
| Feedback: | http://TWiki.org/cgi-bin/view/Plugins/SsoLoginContribDev |
| Appraisal: | http://TWiki.org/cgi-bin/view/Plugins/SsoLoginContribAppraisal |
| I | Attachment | History | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|---|
| |
SsoLoginContrib.md5 | r4 r3 r2 r1 | manage | 0.2 K | 2013-09-26 - 21:26 | PeterThoeny | |
| |
SsoLoginContrib.tgz | r4 r3 r2 r1 | manage | 78.9 K | 2013-09-26 - 21:26 | PeterThoeny | |
| |
SsoLoginContrib.zip | r4 r3 r2 r1 | manage | 81.9 K | 2013-09-26 - 21:26 | PeterThoeny | |
| |
SsoLoginContrib_installer | r2 r1 | manage | 3.5 K | 2013-09-26 - 21:26 | PeterThoeny |