root/platform/tdiary/plugin/openid.rb @ 38791

Revision 35130, 4.2 kB (checked in by kazuhiko, 5 years ago)

* disable Videntity.org because it seems to be closed.
* do not raise an exception if specified service is missing.

Line 
1#
2# openid.rb: Insert OpenID delegation information. $Revision: 1.10 $
3#
4# Copyright (C) 2005, TADA Tadashi <sho@spc.gr.jp>
5# You can redistribute it and/or modify it under GPL2.
6#
7
8@openid_config = (Struct.const_defined?("OpenIdConfig") ? Struct::OpenIdConfig :
9        Struct.new("OpenIdConfig", :openid, :openid2, :x_xrds_location))
10
11if /^(?:latest|conf|saveconf)$/ =~ @mode then
12        @openid_list = {
13                # service => @openid_config.new(
14                #    [openid.server, openid.delegate(replace <ID> as account name)],   # openid
15                #    [openid2.provider, openid2.local_id(replace <ID> as account name)], # openid2
16                #    'X-XRDS-Location(replace <ID> as account name)'),
17                'Hatena' => @openid_config.new(['https://www.hatena.ne.jp/openid/server', 'http://www.hatena.ne.jp/<ID>/']),
18                'livedoor' => @openid_config.new(['http://auth.livedoor.com/openid/server', 'http://profile.livedoor.com/<ID>']),
19                'LiveJournal' => @openid_config.new(['http://www.livejournal.com/openid/server.bml', 'http://<ID>.livejournal.com/']),
20                'OpenID.ne.jp' => @openid_config.new(
21                        ['http://www.openid.ne.jp/user/auth', 'http://<ID>.openid.ne.jp'],
22                        nil,
23                        'http://<ID>.openid.ne.jp/user/xrds'),
24                'TypeKey' => @openid_config.new(['http://www.typekey.com/t/openid/', 'http://profile.typekey.com/<ID>/']),
25                # Videntity.org seems to be closed.
26                # 'Videntity.org' => @openid_config.new(['http://videntity.org/serverlogin?action=openid', 'http://<ID>.videntity.org/']),
27                'Vox' => @openid_config.new(['http://www.vox.com/services/openid/server', 'http://<ID>.vox.com/']),
28                'myopenid.com' => @openid_config.new(
29                        ['http://www.myopenid.com/server', 'http://<ID>.myopenid.com'], # openid
30                        ['http://www.myopenid.com/server', 'http://<ID>.myopenid.com'], # openid2
31                        "http://www.myopenid.com/xrds?username=<ID>"),
32                'claimID.com' => @openid_config.new(
33                        ['http://openid.claimid.com/server', 'http://openid.claimid.com/<ID>'],
34                        nil, #['http://openid.claimid.com/server', 'http://openid.claimid.com/<ID>'],
35                        'http://claimid.com/<ID>/xrds'),
36                'Personal Identity Provider (PIP)' => @openid_config.new(
37                        ['http://pip.verisignlabs.com/server', 'http://<ID>.pip.verisignlabs.com/'],
38                        ['http://pip.verisignlabs.com/server', 'http://<ID>.pip.verisignlabs.com/'],
39                        'http://pip.verisignlabs.com/user/<ID>/yadisxrds'),
40                'Yahoo! Japan' => @openid_config.new(
41                        nil,
42                        ['https://open.login.yahooapis.jp/openid/op/auth', 'https://me.yahoo.co.jp/a/<ID>'],
43                        'http://open.login.yahoo.co.jp/openid20/www.yahoo.co.jp/xrds'),
44                'Yahoo!' => @openid_config.new(
45                        nil,
46                        ['https://open.login.yahooapis.com/openid/op/auth', 'https://me.yahoo.com/a/<ID>'],
47                        'http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds'),
48                'Wassr' => @openid_config.new(['https://wassr.jp/open_id/auth', 'https://wassr.jp/user/<ID>']),
49        }
50
51        if @conf['openid.service'] and @conf['openid.id'] then
52                openid_service = @openid_list[@conf['openid.service']]
53                openid_id = @conf['openid.id']
54                result = ''
55                add_header_proc do
56                        result = <<-HTML if openid_service.openid
57                        <link rel="openid.server" href="#{h openid_service.openid[0]}">
58                        <link rel="openid.delegate" href="#{h openid_service.openid[1].sub( /<ID>/, openid_id )}">
59                        HTML
60                        result << <<-HTML if openid_service.openid2
61                        <link rel="openid2.provider" href="#{h openid_service.openid2[0]}">
62                        <link rel="openid2.local_id" href="#{h openid_service.openid2[1].sub( /<ID>/, openid_id )}">
63                        HTML
64                        result << <<-HTML if openid_service.x_xrds_location
65                        <meta http-equiv="X-XRDS-Location" content="#{h openid_service.x_xrds_location.sub( /<ID>/, openid_id )}">
66                        HTML
67                        result.gsub( /^\t{2}/, '' )
68                end if openid_service
69        end
70end
71
72add_conf_proc( 'openid', @openid_conf_label ) do
73        if @mode == 'saveconf' then
74                @conf['openid.service'] = @cgi.params['openid.service'][0]
75                @conf['openid.id'] = @cgi.params['openid.id'][0]
76        end
77
78        options = ''
79        @openid_list.each_key do |key|
80                options << %Q|<option value="#{h key}"#{" selected" if @conf['openid.service'] == key}>#{h key}</option>\n|
81        end
82        <<-HTML
83        <h3 class="subtitle">#{@openid_service_label}</h3>
84        <p>#{@openid_service_desc}</p>
85        <p><select name="openid.service">
86                #{options}
87        </select></p>
88
89        <h3 class="subtitle">#{@openid_id_label}</h3>
90        <p>#{@openid_id_desc}</p>
91        <p><input name="openid.id" value="#{h @conf['openid.id']}"></p>
92        HTML
93end
Note: See TracBrowser for help on using the browser.