forked from brett19/php-couchbase
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcertauth.php
More file actions
21 lines (19 loc) · 1.14 KB
/
certauth.php
File metadata and controls
21 lines (19 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
// This example uses X.509 certificates to authenticate on Couchbase Server
// Read more about this feature at
//
// https://developer.couchbase.com/documentation/server/5.0/security/security-x509certsintro.html
//
// Also helper script, which generates certificates for local cluster, could be found here:
//
// https://gist.github.com/avsej/e1a05532b605ddd3a282734a6049a858
// Certificate chain, which includes client public certificate (going first), and then concatenated with intermediate
// and root certificates if they are not part of the system trusted certificates.
$cert = "/tmp/x509-cert/SSLCA/clientdir/chain.pem";
// Private key for the client. Note that the username should be embedded into certificate on the generation stage into
// corresponding field. In our example, we use CN and user "testuser", which has access to bucket "default".
$key = "/tmp/x509-cert/SSLCA/clientdir/client.key";
// NOTE: that it have to use "couchbases://" schema ("https://" will also work)
$cluster = new \Couchbase\Cluster("couchbases://127.0.0.1?certpath=$cert&keypath=$key");
$bucket = $cluster->openBucket("default");
$bucket->upsert("foo", ["bar" => 42]);