# Mock Google OIDC Provider

A lightweight mock OpenID Connect provider that simulates Google login for local MAS development. It lets you test the upstream OAuth2 / "Sign in with Google" flow without needing real Google credentials.

## Prerequisites

- Node.js 18+
- MAS configured with an upstream OAuth2 provider pointing to this mock

## Quick start

```sh
cd mocks/mock-google-oidc
npm install
npm start
```

The server starts at `http://localhost:5556`.

## How it works

The mock uses [`oidc-provider`](https://github.com/panva/node-oidc-provider) to run a standards-compliant OIDC server with dev interactions enabled. When MAS redirects to the mock for login, you'll see a simple form where you can enter any email-like value (e.g. `taylor@gmail.com`). The mock will return that as the authenticated user with synthetic profile claims.

## MAS configuration

Add an upstream OAuth2 provider entry in your MAS `config.yaml`:

```yaml
upstream_oauth2:
  providers:
    - id: "01JQ0FAKEG00G1E0D1CPR0V1D3"
      human_name: "Google"
      issuer: "http://localhost:5556"
      client_id: "mas-dev"
      client_secret: "mas-dev-secret"
      token_endpoint_auth_method: "client_secret_post"
      scope: "openid email profile"
      claims_imports:
        localpart:
          action: suggest
          template: "{{ user.preferred_username }}"
        displayname:
          action: suggest
          template: "{{ user.name }}"
        email:
          action: suggest
          template: "{{ user.email }}"
          set_email_verification: always
```

## Environment variables

| Variable | Default | Description |
|----------|---------|-------------|
| `MOCK_OIDC_ISSUER` | `http://localhost:5556` | The issuer URL |
| `MAS_PROVIDER_ID` | `01JQ0FAKEG00G1E0D1CPR0V1D3` | The upstream provider ID configured in MAS |
| `MOCK_OIDC_CLIENT_ID` | `mas-dev` | OAuth2 client ID |
| `MOCK_OIDC_CLIENT_SECRET` | `mas-dev-secret` | OAuth2 client secret |

## Running with the full dev stack

```sh
# Terminal 1: Mock Synapse (handles homeserver API calls)
python3 mocks/mock_synapse.py

# Terminal 2: Mock Google OIDC
cd mocks/mock-google-oidc && npm start

# Terminal 3: MAS
cargo run -- server -c config.yaml
```

Then visit `http://[::]:8080/login` and click "Sign in with Google".
