auth_dummy.ml 3.06 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) : AUTH_INSTANCE_HANDLERS = struct
36
37

  module L = Web_auth.MakeLinks (N)
38

Stephane Glondu's avatar
Stephane Glondu committed
39
40
  let scope = Eliom_common.default_session_scope

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

Stephane Glondu's avatar
Stephane Glondu committed
46
  let login_cont = Eliom_reference.eref ~scope None
47

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

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

72
73
  let logout cont () = cont () ()

74
end
75

76
let make () = (module Make : AUTH_MAKE_INSTANCE)
77
78
79
80
81
82
83
84

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

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