Debian Codegraph @

doc/src/manual/cowboy_req.cert.asciidoc

raw
1 = cowboy_req:cert(3)
2
3 == Name
4
5 cowboy_req:cert - Client TLS certificate
6
7 == Description
8
9 [source,erlang]
10 ----
11 cert(Req :: cowboy_req:req()) -> binary() | undefined
12 ----
13
14 Return the peer's TLS certificate.
15
16 Using the default configuration this function will always return
17 `undefined`. You need to explicitly configure Cowboy to request
18 the client certificate. To do this you need to set the `verify`
19 transport option to `verify_peer`:
20
21 [source,erlang]
22 ----
23 {ok, _} = cowboy:start_tls(example, [
24 {port, 8443},
25 {certfile, "path/to/cert.pem"},
26 {verify, verify_peer}
27 ], #{
28 env => #{dispatch => Dispatch}
29 }).
30 ----
31
32 You may also want to customize the `verify_fun` function. Please
33 consult the `ssl` application's manual for more details.
34
35 TCP connections do not allow a certificate and this function
36 will therefore always return `undefined`.
37
38 The certificate can also be obtained using pattern matching:
39
40 [source,erlang]
41 ----
42 #{cert := Cert} = Req.
43 ----
44
45 == Arguments
46
47 Req::
48
49 The Req object.
50
51 == Return value
52
53 The client TLS certificate.
54
55 == Changelog
56
57 * *2.1*: Function introduced.
58
59 == Examples
60
61 .Get the client TLS certificate.
62 [source,erlang]
63 ----
64 Cert = cowboy_req:cert(Req).
65 ----
66
67 == See also
68
69 link:man:cowboy_req(3)[cowboy_req(3)],
70 link:man:cowboy_req:peer(3)[cowboy_req:peer(3)],
71 link:man:cowboy_req:sock(3)[cowboy_req:sock(3)]