35
36:- module(swish_authenticate,
37 [ authenticate/2, 38 user_property/2 39 ]). 40:- use_module(library(http/http_wrapper)). 41:- use_module(library(debug)). 42:- use_module(library(broadcast)). 43
44:- use_module(config).
68authenticate(Request, Auth) :-
69 http_peer(Request, Peer),
70 http_auth(Request, Auth0),
71 profile_auth(Request, Auth1),
72 Auth2 = Auth0.put(Auth1).put(peer, Peer),
73 identity(Auth2, Auth),
74 debug(authenticate, 'Identity: ~p', [Auth]).
75
76:- multifile
77 swish_config:user_info/3,
78 swish_config:authenticate/2,
79 swish_config:user_profile/2. 80
81http_auth(Request, Auth) :-
82 ( swish_config:authenticate(Request, User) 83 -> true
84 ; swish_config:user_info(Request, local, UserInfo),
85 User = UserInfo.get(user)
86 ),
87 !,
88 Auth = auth{user:User, identity_provider:local, external_identity:User}.
89http_auth(_Request, auth{}).
90
91profile_auth(Request, Auth) :-
92 swish_config:user_profile(Request, Profile),
93 Auth = _{identity_provider: _,
94 external_identity: _,
95 profile_id:_},
96 Auth :< Profile,
97 !.
98profile_auth(_, auth{}).
99
100identity(Auth0, Auth) :-
101 _{identity_provider:Provider, external_identity:ExtID} :< Auth0,
102 !,
103 atomic_list_concat([Provider,ExtID], :, Identity),
104 Auth = Auth0.put(identity, Identity).
105identity(Auth, Auth).
129user_property(Identity, Property) :-
130 current_user_property(Property, How),
131 user_property_impl(Property, How, Identity).
132
133user_property_impl(Property, dict, Identity) :- !,
134 Property =.. [Name,Value],
135 Value = Identity.get(Name).
136user_property_impl(Property, broadcast, Identity) :-
137 broadcast_request(identity_property(Identity, Property)).
138user_property_impl(login(By), _, Identity) :-
139 By = Identity.get(identity_provider).
140
141
142current_user_property(peer(_Atom), dict).
143current_user_property(identity(_Atom), dict).
144current_user_property(external_identity(_String), dict).
145current_user_property(identity_provider(_Atom), dict).
146current_user_property(profile_id(_Atom), dict).
147
148current_user_property(login(_IdProvider), derived).
149current_user_property(name(_Name), broadcast).
150current_user_property(email(_Email), broadcast).
151
152
153
162:- multifile pengines:authentication_hook/3. 163
164pengines:authentication_hook(Request, _Application, User) :-
165 authenticate(Request, User)
Authentication access for SWISH
This module (depending on the loaded configuration) identifies the user based on the HTTP request.
pep.pl
for authorization issues. */