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

Revision 5950, 4.0 kB (checked in by drry, 6 years ago)

platform/tdiary/plugin/openid.rb: added XRDS Yadis for Yahoo!

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' => @openid_config.new(['http://videntity.org/serverlogin?action=openid', 'http://<ID>.videntity.org/']),
26                'Vox' => @openid_config.new(['http://www.vox.com/services/openid/server', 'http://<ID>.vox.com/']),
27                'myopenid.com' => @openid_config.new(
28                        ['http://www.myopenid.com/server', 'http://<ID>.myopenid.com'], # openid
29                        ['http://www.myopenid.com/server', 'http://<ID>.myopenid.com'], # openid2
30                        "http://www.myopenid.com/xrds?username=<ID>"),
31                'claimID.com' => @openid_config.new(
32                        ['http://openid.claimid.com/server', 'http://openid.claimid.com/<ID>'],
33                        nil, #['http://openid.claimid.com/server', 'http://openid.claimid.com/<ID>'],
34                        'http://claimid.com/<ID>/xrds'),
35                'Personal Identity Provider (PIP)' => @openid_config.new(
36                        ['http://pip.verisignlabs.com/server', 'http://<ID>.pip.verisignlabs.com/'],
37                        ['http://pip.verisignlabs.com/server', 'http://<ID>.pip.verisignlabs.com/'],
38                        'http://pip.verisignlabs.com/user/<ID>/yadisxrds'),
39                'Yahoo! Japan' => @openid_config.new(
40                        nil,
41                        ['https://open.login.yahooapis.jp/openid/op/auth', 'https://me.yahoo.co.jp/a/<ID>'],
42                        'http://open.login.yahoo.co.jp/openid20/www.yahoo.co.jp/xrds'),
43                'Yahoo!' => @openid_config.new(
44                        nil,
45                        ['https://open.login.yahooapis.com/openid/op/auth', 'https://me.yahoo.com/a/<ID>'],
46                        'http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds'),
47        }
48
49        if @conf['openid.service'] and @conf['openid.id'] then
50                openid_service = @openid_list[@conf['openid.service']]
51                openid_id = @conf['openid.id']
52                result = ''
53                add_header_proc do
54                        result = <<-HTML if openid_service.openid
55                        <link rel="openid.server" href="#{h openid_service.openid[0]}">
56                        <link rel="openid.delegate" href="#{h openid_service.openid[1].sub( /<ID>/, openid_id )}">
57                        HTML
58                        result << <<-HTML if openid_service.openid2
59                        <link rel="openid2.provider" href="#{h openid_service.openid2[0]}">
60                        <link rel="openid2.local_id" href="#{h openid_service.openid2[1].sub( /<ID>/, openid_id )}">
61                        HTML
62                        result << <<-HTML if openid_service.x_xrds_location
63                        <meta http-equiv="X-XRDS-Location" content="#{h openid_service.x_xrds_location.sub( /<ID>/, openid_id )}">
64                        HTML
65                        result.gsub( /^\t{2}/, '' )
66                end
67        end
68end
69
70add_conf_proc( 'openid', @openid_conf_label ) do
71        if @mode == 'saveconf' then
72                @conf['openid.service'] = @cgi.params['openid.service'][0]
73                @conf['openid.id'] = @cgi.params['openid.id'][0]
74        end
75
76        options = ''
77        @openid_list.each_key do |key|
78                options << %Q|<option value="#{h key}"#{" selected" if @conf['openid.service'] == key}>#{h key}</option>\n|
79        end
80        <<-HTML
81        <h3 class="subtitle">#{@openid_service_label}</h3>
82        <p>#{@openid_service_desc}</p>
83        <p><select name="openid.service">
84                #{options}
85        </select></p>
86
87        <h3 class="subtitle">#{@openid_id_label}</h3>
88        <p>#{@openid_id_desc}</p>
89        <p><input name="openid.id" value="#{h @conf['openid.id']}"></p>
90        HTML
91end
Note: See TracBrowser for help on using the browser.