Chris@0
|
1 /* This file is part of ClioPatria.
|
Chris@0
|
2
|
Chris@0
|
3 Author:
|
Chris@0
|
4 HTTP: http://e-culture.multimedian.nl/
|
Chris@0
|
5 GITWEB: http://gollem.science.uva.nl/git/ClioPatria.git
|
Chris@0
|
6 GIT: git://gollem.science.uva.nl/home/git/ClioPatria.git
|
Chris@0
|
7 GIT: http://gollem.science.uva.nl/home/git/ClioPatria.git
|
Chris@0
|
8 Copyright: 2007, E-Culture/MultimediaN
|
Chris@0
|
9
|
Chris@0
|
10 ClioPatria is free software: you can redistribute it and/or modify
|
Chris@0
|
11 it under the terms of the GNU General Public License as published by
|
Chris@0
|
12 the Free Software Foundation, either version 2 of the License, or
|
Chris@0
|
13 (at your option) any later version.
|
Chris@0
|
14
|
Chris@0
|
15 ClioPatria is distributed in the hope that it will be useful,
|
Chris@0
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
18 GNU General Public License for more details.
|
Chris@0
|
19
|
Chris@0
|
20 You should have received a copy of the GNU General Public License
|
Chris@0
|
21 along with ClioPatria. If not, see <http://www.gnu.org/licenses/>.
|
Chris@0
|
22 */
|
Chris@0
|
23
|
Chris@0
|
24 :- asserta(file_search_path(library, '..')).
|
Chris@0
|
25
|
Chris@0
|
26 :- use_module(http_openid).
|
Chris@0
|
27 :- use_module(library('http/http_dispatch')).
|
Chris@0
|
28 :- use_module(library('http/http_error')).
|
Chris@0
|
29 :- use_module(library('http/thread_httpd')).
|
Chris@0
|
30 :- use_module(library('http/html_write')).
|
Chris@0
|
31 :- use_module(library(plunit)).
|
Chris@0
|
32
|
Chris@0
|
33 :- debug(openid(_)).
|
Chris@0
|
34 %:- debug(http(_)).
|
Chris@0
|
35
|
Chris@0
|
36 consumer(Port) :-
|
Chris@0
|
37 http_server(http_dispatch,
|
Chris@0
|
38 [ port(Port)
|
Chris@0
|
39 ]).
|
Chris@0
|
40
|
Chris@0
|
41
|
Chris@0
|
42 assoc :-
|
Chris@0
|
43 openid_associate('http://localhost:8001/openid/server', Handle, Assoc),
|
Chris@0
|
44 writeln(Handle-Assoc).
|
Chris@0
|
45
|
Chris@0
|
46 %% secret(+Request) is det.
|
Chris@0
|
47 %
|
Chris@0
|
48 % Example of a handler that requires an OpenID login. If the user
|
Chris@0
|
49 % is not logged it, it will be redirected to the login page, from
|
Chris@0
|
50 % there to the OpenID server and back here. All this is completely
|
Chris@0
|
51 % transparent to us.
|
Chris@0
|
52
|
Chris@0
|
53 :- http_handler('/secret', secret, []).
|
Chris@0
|
54
|
Chris@0
|
55 secret(Request) :-
|
Chris@0
|
56 openid_user(Request, User, []),
|
Chris@0
|
57 reply_html_page(title('Secret'),
|
Chris@0
|
58 [ 'You\'ve reached the secret page as user ',
|
Chris@0
|
59 a(href(User), User)
|
Chris@0
|
60 ]).
|
Chris@0
|
61
|
Chris@0
|
62 %% root(+Request).
|
Chris@0
|
63 %% allow(+Request).
|
Chris@0
|
64 %
|
Chris@0
|
65 % Shows an indirect login.
|
Chris@0
|
66
|
Chris@0
|
67 :- http_handler(/, root, []).
|
Chris@0
|
68 :- http_handler('/test/verify', openid_verify([return_to(allow)]), []).
|
Chris@0
|
69 :- http_handler('/test/allow', allow, []).
|
Chris@0
|
70
|
Chris@0
|
71 root(_Request) :-
|
Chris@0
|
72 reply_html_page(title('Demo OpenID consumer'),
|
Chris@0
|
73 [ h1('OpenID consumer'),
|
Chris@0
|
74 form([ name(login),
|
Chris@0
|
75 action('/test/verify'),
|
Chris@0
|
76 method('GET')
|
Chris@0
|
77 ],
|
Chris@0
|
78 [ div([ 'OpenID: ',
|
Chris@0
|
79 input([ name(openid_url),
|
Chris@0
|
80 size(40),
|
Chris@0
|
81 value('http://localhost:8000/bob') % test
|
Chris@0
|
82 ]),
|
Chris@0
|
83 input([type(submit), value('Verify!')])
|
Chris@0
|
84 ])
|
Chris@0
|
85 ]),
|
Chris@0
|
86 p([ 'Or go directly to the ', a(href=secret, 'secret page') ])
|
Chris@0
|
87 ]).
|
Chris@0
|
88
|
Chris@0
|
89
|
Chris@0
|
90 allow(Request) :-
|
Chris@0
|
91 openid_authenticate(Request, Server, Identity, ReturnTo),
|
Chris@0
|
92 reply_html_page(title('Success'),
|
Chris@0
|
93 [ h1('OpenID login succeeded'),
|
Chris@0
|
94 p([ 'The OpenID server ',
|
Chris@0
|
95 a(href(Server),Server),
|
Chris@0
|
96 ' verified you as ',
|
Chris@0
|
97 a(href(Identity), Identity)
|
Chris@0
|
98 ]),
|
Chris@0
|
99 p(['Redirect to ', a(href(ReturnTo), ReturnTo)])
|
Chris@0
|
100 ]).
|
Chris@0
|
101
|
Chris@0
|
102
|
Chris@0
|
103 /*******************************
|
Chris@0
|
104 * OpenID SERVER *
|
Chris@0
|
105 *******************************/
|
Chris@0
|
106
|
Chris@0
|
107 :- http_handler(prefix('/user/'), user_page, []).
|
Chris@0
|
108 :- http_handler('/openid/server', openid_server([]), []).
|
Chris@0
|
109
|
Chris@0
|
110 %% user_page(+Request) is det.
|
Chris@0
|
111 %
|
Chris@0
|
112 % Generate a page for user below /user/<user>.
|
Chris@0
|
113
|
Chris@0
|
114 user_page(Request) :-
|
Chris@0
|
115 http_openid:current_root_url(Request, Root),
|
Chris@0
|
116 atom_concat(Root, 'openid/server', Me),
|
Chris@0
|
117 memberchk(path(Path), Request),
|
Chris@0
|
118 atom_concat('/user/', User, Path),
|
Chris@0
|
119 reply_html_page([ link([ rel('openid.server'),
|
Chris@0
|
120 href(Me)
|
Chris@0
|
121 ]),
|
Chris@0
|
122 title('OpenID page of ~w'-[User])
|
Chris@0
|
123 ],
|
Chris@0
|
124 h1('OpenID page of ~w'-[User])).
|
Chris@0
|
125
|
Chris@0
|
126
|
Chris@0
|
127 /*******************************
|
Chris@0
|
128 * DEBUG *
|
Chris@0
|
129 *******************************/
|
Chris@0
|
130
|
Chris@0
|
131 :- http_handler(prefix(/), print_request, []).
|
Chris@0
|
132
|
Chris@0
|
133 print_request(Request) :-
|
Chris@0
|
134 format('Content-type: text/plain~n~n'),
|
Chris@0
|
135 pp(Request).
|