auth_dummy.ml 3.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
(*  Copyright © 2012-2014 Inria                                           *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU Affero General Public License as        *)
(*  published by the Free Software Foundation, either version 3 of the    *)
(*  License, or (at your option) any later version, with the additional   *)
(*  exemption that compiling, linking, and/or using OpenSSL is allowed.   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful, but   *)
(*  WITHOUT ANY WARRANTY; without even the implied warranty of            *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Affero General Public License for more details.                       *)
(*                                                                        *)
(*  You should have received a copy of the GNU Affero General Public      *)
(*  License along with this program.  If not, see                         *)
(*  <http://www.gnu.org/licenses/>.                                       *)
(**************************************************************************)

22
open Lwt
23
open Web_signatures
24
open Web_common
25
26
27
28
29

type config = unit

let name = "dummy"

30
let parse_config ~attributes =
31
  match attributes with
32
33
  | [] -> Some ()
  | _ -> None
34

35
module Make (N : NAME) (S : AUTH_SERVICES) (L : AUTH_LINKS) : AUTH_HANDLERS = struct
36

Stephane Glondu's avatar
Stephane Glondu committed
37
38
  let scope = Eliom_common.default_session_scope

Stephane Glondu's avatar
Stephane Glondu committed
39
  let service = Eliom_service.Http.service
40
    ~path:N.path
41
42
    ~get_params:Eliom_parameter.unit
    ()
43

Stephane Glondu's avatar
Stephane Glondu committed
44
  let login_cont = Eliom_reference.eref ~scope None
45

46
47
48
  let () = Eliom_registration.Html5.register ~service
    (fun () () ->
      let post_params = Eliom_parameter.(string "username") in
Stephane Glondu's avatar
Stephane Glondu committed
49
      let service = Eliom_service.Http.post_coservice
50
        ~csrf_safe:true
Stephane Glondu's avatar
Stephane Glondu committed
51
        ~csrf_scope:scope
52
53
54
        ~fallback:service
        ~post_params ()
      in
Stephane Glondu's avatar
Stephane Glondu committed
55
      let () = Eliom_registration.Any.register ~service ~scope
56
        (fun () user_name ->
57
58
59
60
61
62
          match_lwt Eliom_reference.get login_cont with
          | Some cont ->
            Eliom_reference.unset login_cont >>
            cont user_name ()
          | None -> fail_http 400
        )
63
      in Web_templates.dummy ~service (module S : AUTH_SERVICES) (module L : AUTH_LINKS) ()
64
    )
65

66
67
  let login cont () =
    Eliom_reference.set login_cont (Some cont) >>
68
    Eliom_registration.Redirection.send service
69

70
71
  let logout cont () = cont () ()

72
end
73

74
75
76
77
78
79
80
81
82
let make () = (module Make : AUTH_SERVICE)

module A : AUTH_SYSTEM = struct
  type config = unit
  let name = name
  let parse_config = parse_config
  let make = make
end

83
let () = Web_auth.register_auth_system (module A : AUTH_SYSTEM)