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

Revision 5138, 3.6 kB (checked in by drry, 7 years ago)

platform/tdiary/plugin/openid.rb: pound よりも URL として使われえない記号に。

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        }
40
41        if @conf['openid.service'] and @conf['openid.id'] then
42                openid_service = @openid_list[@conf['openid.service']]
43                openid_id = @conf['openid.id']
44                add_header_proc do
45                        result = <<-HTML
46                        <link rel="openid.server" href="#{h openid_service.openid[0]}">
47                        <link rel="openid.delegate" href="#{h openid_service.openid[1].sub( /<ID>/, openid_id )}">
48                        HTML
49                        result << <<-HTML if openid_service.openid2
50                        <link rel="openid2.provider" href="#{h openid_service.openid2[0]}">
51                        <link rel="openid2.local_id" href="#{h openid_service.openid2[1].sub( /<ID>/, openid_id )}">
52                        HTML
53                        result << <<-HTML if openid_service.x_xrds_location
54                        <meta http-equiv="X-XRDS-Location" content="#{h openid_service.x_xrds_location.sub( /<ID>/, openid_id )}">
55                        HTML
56                        result.gsub( /^\t{2}/, '' )
57                end
58        end
59end
60
61add_conf_proc( 'openid', @openid_conf_label ) do
62        if @mode == 'saveconf' then
63                @conf['openid.service'] = @cgi.params['openid.service'][0]
64                @conf['openid.id'] = @cgi.params['openid.id'][0]
65        end
66
67        options = ''
68        @openid_list.each_key do |key|
69                options << %Q|<option value="#{h key}"#{" selected" if @conf['openid.service'] == key}>#{h key}</option>\n|
70        end
71        <<-HTML
72        <h3 class="subtitle">#{@openid_service_label}</h3>
73        <p>#{@openid_service_desc}</p>
74        <p><select name="openid.service">
75                #{options}
76        </select></p>
77
78        <h3 class="subtitle">#{@openid_id_label}</h3>
79        <p>#{@openid_id_desc}</p>
80        <p><input name="openid.id" value="#{h @conf['openid.id']}"></p>
81        HTML
82end
Note: See TracBrowser for help on using the browser.