# Auth Wrapper

## Module `teacherhelper.google.client`

Google has thorough documentation for their
[python client libraries](https://github.com/googleapis/google-api-python-client)

This module wraps those libraries, and uses the helper data directory to load
the credentials you will need to create, and to store tokens generated by the
Oauth authentication process.

## Setup

This wraps google's python oauth client libraries, but uses `$HELPER_DATA` for
reading your credentials and storing your authentication token. To use this
module or it's dependencies, you will need to generate Ouath credentials on the
Google Cloud Platform. See [Using OAuth 2.0 to Access Google
APIs.](https://developers.google.com/identity/protocols/oauth2)

After you get Oauth client credentials, put the `credentials.json` file in
`$HELPER_DATA/google_oauth/credentials.json`. For more about the helper data
dir, see [setup.](../setup.md) The google client module will also store the
Oauth token in `$HELPER_DATA/google_oauth/token.json`, so that you only
need to login the first time.

You need to make sure that your Oauth token at least supports the following
scopes, as well as any others that you wish to use:

```
openid
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/presentations.readonly
https://www.googleapis.com/auth/classroom.courses.readonly
https://www.googleapis.com/auth/classroom.courseworkmaterials.readonly
https://www.googleapis.com/auth/classroom.student-submissions.students.readonly
https://www.googleapis.com/auth/classroom.rosters.readonly
https://www.googleapis.com/auth/classroom.profile.photos
https://www.googleapis.com/auth/drive.readonly
```

The client wrapper will use the authentication scopes defined in
`google_client.ClientWrapper.DEFAULT_SCOPES`, which are the same as the ones
documented in the previous section. These default scopes are used by the main
ClientWrapper class, and also by the convenience functions, `get_service` and
`get_credentials`.

## Convenience Functions

**`google_client.get_service(service: str, version: str)`**

Get one of the Google python client's service objects. These objects store
your authentication context, and can be used to interact with various Google
services.

**`google_client.get_credentials()`**

Return the raw credentials object. This can be useful if you're using the
google account to authenticate with a third party service via an Oauth client
token. For example, I used this to access grades I had input on my [Fast
Grader Website](https://classfast.app/).

## ClientWrapper Class (`google_client.ClientWrapper`)

Main client wrapper class.

**`ClientWrapper.BASE_DIR: Path`**

Path to `$HELPER_DATA/google_oauth`

**`ClientWrapper.CREDENTIALS` and `ClientWrapper.TOKEN`**

Path to `$HELPER_DATA/google_oauth/credentials.json` and
`$HELPER_DATA/google_oauth/token.json, respectively`

**`ClientWrapper.get_credentials(self): google.oauth2.credentials.Credentials`**

Method to fetch credentials, first checking for a valid cached token.

**`ClientWrapper.get_service(self, service: str, version: str)`**

Method to create a google client service object
