Skip to content

Commit e75533a

Browse files
committed
Add section to readme about user auth
1 parent f5ac60a commit e75533a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ if err != nil {
9191

9292
When `DiscoverHosts` is true any nodes are added to the cluster after the initial connection then the new node will be added to the pool of available nodes used by GoRethink. Unfortunately the canonical address of each server in the cluster **MUST** be set as otherwise clients will try to connect to the database nodes locally. For more information about how to set a RethinkDB servers canonical address set this page http://www.rethinkdb.com/docs/config-file/.
9393

94+
## User Authentication
95+
96+
To login with a username and password you should first create a user, this can be done by writing to the `users` system table and then grant that user access to any tables or databases they need access to. This queries can also be executed in the RethinkDB admin console.
97+
98+
```go
99+
err := r.DB("rethinkdb").Table("users").Insert(map[string]string{
100+
"id": "john",
101+
"password": "p455w0rd",
102+
}).Exec(session)
103+
...
104+
err = r.DB("blog").Table("posts").Grant("john", map[string]bool{
105+
"read": true,
106+
"write": true,
107+
}).Exec(session)
108+
...
109+
```
110+
111+
Finally the username and password should be passed to `Connect` when creating your session, for example:
112+
113+
```go
114+
session, err := r.Connect(r.ConnectOpts{
115+
Address: "localhost:28015",
116+
Database: "blog",
117+
Username: "john",
118+
Password: "p455w0rd",
119+
})
120+
```
121+
122+
Please note that `DiscoverHosts` will not work with user authentication at this time due to the fact that RethinkDB restricts access to the required system tables.
94123

95124
## Query Functions
96125

0 commit comments

Comments
 (0)