Skip to content

Commit 1dd429d

Browse files
committed
Add API auth docs
1 parent 2f58d40 commit 1dd429d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/api_authentication.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Google API Authentication
2+
3+
Metadocs is compatible with the [Credentials](https://www.rubydoc.info/github/google/google-auth-library-ruby/Google/Auth/Credentials)
4+
object used by the official [googleauth](https://github.com/googleapis/google-auth-library-ruby)
5+
library.
6+
7+
There are different ways to authenticate with Google:
8+
9+
- on behalf of end users with OAuth2, for web or console applications;
10+
- with a service account.
11+
12+
See the [googleauth](https://github.com/googleapis/google-auth-library-ruby) docs for more info.
13+
14+
Either option will work with this library - what's important is to pass on the `Credentials` created
15+
by `googleauth`.
16+
17+
The scopes you need to authorize for are provided in `Metadocs::GoogleDocument::RequiredScopes`.
18+
Currently only `https://www.googleapis.com/auth/documents` is needed.
19+
20+
## Example
21+
22+
```ruby
23+
credentials = Google::Auth::ServiceAccountCredentials.make_creds(
24+
json_key_io: File.open('/path/to/service_account_json_key.json'),
25+
scope: Metadocs::GoogleDocument::RequiredScopes
26+
)
27+
28+
metadoc = Metadocs::Parser.parse(credentials, 'https://docs.google.com/document/d/...')
29+
```
30+
31+
## Permissions
32+
33+
Note that the credentials object must have permission to view the document you're trying to access.
34+
35+
For on behalf authorization, that means the user you're accessing data on behalf of has permission
36+
to view the document.
37+
38+
For service accounts, you can share the document with the service account
39+
e-mail that shows up in the `client_email` property of the service account credentials JSON file
40+
exported by Google.

0 commit comments

Comments
 (0)