# oauth


## Preset

``` python
def Preset(
    scopes:tuple=(), apis:tuple=()
):
```

*OAuth scopes and the Google APIs they need; `+` unions two presets in order*

## oauth_config

``` python
def oauth_config(
    preset:str='google-apps', scopes=None, apis=None
)->gclientid.oauth.Preset:
```

*The preset’s scopes and APIs plus any additions, deduplicated*

## connect_browser

``` python
async def connect_browser(
    default_browser:bool=True, # Use normal Chrome instead of CDP Chrome?
    timeout:int=60, # Seconds to wait for normal Chrome's approval
)->tuple[fastcdp.core.CDP, fastcdp.core.Page]:
```

*Connect to Chrome and return its connection and a new page*

## setup_auth

``` python
async def setup_auth(
    page:fastcdp.core.Page, # Signed-in Google Cloud Console page
    project_id:str, # Existing Google Cloud project ID
    name:str='gclientids', # OAuth application name
    internal:bool=False, # Restrict authorization to the project's organization?
    support_email:str=None, # Require this support/contact email in the signed-in Console session
    accept_terms:bool=True, # Accept Google's API Services terms without pausing?
    timeout:int=10, # Seconds to wait for each Console operation
    terms_timeout:int=600, # Seconds to wait for manual terms acceptance
):
```

*Initialize the OAuth app’s name, audience, and contact details unless it already exists*

## set_branding

``` python
async def set_branding(
    page:fastcdp.core.Page, project_id:str, timeout:int=10
):
```

*Set gclientid’s homepage, privacy URL, and authorized domain; return whether anything changed*

## set_scopes

``` python
async def set_scopes(
    page:fastcdp.core.Page, project_id:str,
    scopes:tuple=('openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://mail.google.com/', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/contacts', 'https://www.googleapis.com/auth/contacts.other.readonly', 'https://www.googleapis.com/auth/directory.readonly', 'https://www.googleapis.com/auth/tasks', 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit', 'https://www.googleapis.com/auth/admin.directory.domain', 'https://www.googleapis.com/auth/admin.directory.resource.calendar', 'https://www.googleapis.com/auth/admin.directory.rolemanagement', 'https://www.googleapis.com/auth/admin.reports.audit.readonly', 'https://www.googleapis.com/auth/admin.reports.usage.readonly', 'https://www.googleapis.com/auth/apps.licensing', 'https://www.googleapis.com/auth/colaboratory'),
    timeout:int=10
):
```

*Add missing declared scopes without removing existing scopes; return the added scopes*

## publish_app

``` python
async def publish_app(
    page:fastcdp.core.Page, project_id:str, timeout:int=10
):
```

*Publish an External OAuth app unless it is already in production; do not use for Internal apps*

## console_account

``` python
async def console_account(
    page:fastcdp.core.Page, timeout:int=10
)->str:
```

*Email of the Google account signed into the Cloud Console*

## configure_app

``` python
async def configure_app(
    page:fastcdp.core.Page, # Signed-in Google Cloud Console page
    project_id:str, # Existing Google Cloud project ID
    name:str='gclientids', # OAuth application name
    scopes:tuple=('openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://mail.google.com/', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/contacts', 'https://www.googleapis.com/auth/contacts.other.readonly', 'https://www.googleapis.com/auth/directory.readonly', 'https://www.googleapis.com/auth/tasks', 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit', 'https://www.googleapis.com/auth/admin.directory.domain', 'https://www.googleapis.com/auth/admin.directory.resource.calendar', 'https://www.googleapis.com/auth/admin.directory.rolemanagement', 'https://www.googleapis.com/auth/admin.reports.audit.readonly', 'https://www.googleapis.com/auth/admin.reports.usage.readonly', 'https://www.googleapis.com/auth/apps.licensing', 'https://www.googleapis.com/auth/colaboratory'), # Scopes to declare on the Data Access page
    internal:bool=False, # Restrict OAuth authorization to the Cloud project's organization?
    support_email:str=None, # Require this support/contact email in the signed-in Console session
    accept_terms:bool=True, # Accept Google's API Services terms without pausing?
    timeout:int=10, # Seconds to wait for each Console operation
    terms_timeout:int=600, # Seconds to wait while the developer handles the terms screen
):
```

*Idempotently configure the project’s OAuth app: audience, branding, declared scopes, and publication*

## create_client

``` python
async def create_client(
    page:fastcdp.core.Page, # Signed-in Google Cloud Console page
    project_id:str, # Google Cloud project ID whose OAuth app `configure_app` has set up
    path:str | pathlib._local.Path='oauth-client.json', # Destination for Google's client JSON
    name:str='gclientids', # OAuth client name
    desktop:bool=False, # Create a Desktop client instead of a Web client?
    redirects:tuple=('http://127.0.0.1:53682/', 'https://oauth.appapis.org/redirect', 'http://localhost:5001/redirect', 'http://127.0.0.1:5001/redirect', 'http://localhost:5002/redirect', 'http://127.0.0.1:5002/redirect', 'http://localhost:8000/redirect', 'http://127.0.0.1:8000/redirect', 'http://localhost:8080/redirect', 'http://127.0.0.1:8080/redirect'), # Authorized redirect URIs of a Web client
    timeout:int=10, # Seconds to wait for each Console operation
)->dict:
```

*Create an OAuth client and save its client JSON, in Google’s `web` or `installed` shape*

## add_redirects

``` python
async def add_redirects(
    page:fastcdp.core.Page, # Signed-in Google Cloud Console page
    path:str | pathlib._local.Path, # Stored Web client JSON
    redirects:tuple=('http://127.0.0.1:53682/', 'https://oauth.appapis.org/redirect', 'http://localhost:5001/redirect', 'http://127.0.0.1:5001/redirect', 'http://localhost:5002/redirect', 'http://127.0.0.1:5002/redirect', 'http://localhost:8000/redirect', 'http://127.0.0.1:8000/redirect', 'http://localhost:8080/redirect', 'http://127.0.0.1:8080/redirect'), # Redirect URIs that must be registered
    timeout:int=10, # Seconds to wait for each Console operation
)->list:
```

*Register any of `redirects` the Web client lacks, in Google and in its JSON; returns the registered list*

## authorize_google

``` python
async def authorize_google(
    client_path:str | pathlib._local.Path='oauth-client.json', # Web or Desktop client JSON from create_client
    token_path:str | pathlib._local.Path='oauth-token.json', # Destination for access and refresh token JSON
    preset:str='google-apps', # Scope preset
    scopes=None, # Additional OAuth scopes
    account:str=None, # Google account email hint and verification
    cdp:fastcdp.core.CDP=None, # Existing CDP connection; the default browser if omitted
    remote:bool=False, # Use appapis copy/paste instead of a local callback (Web clients only)?
    open_browser:bool=True, # Open the appapis authorization URL in the default browser?
)->dict:
```

*Authorize Google APIs and save refreshable token JSON*
