# `connection.scope_not_requested`

A call through a connection whose credential is an OAuth grant reaches an operation whose scope the connection's `scopes:` doesn't ask for.

Area 11, [External services](/docs/external-services.md); not declinable; the next step is usually the human's.

## Why Jadpo refuses it

A connection whose credential is an OAuth grant acts at the provider with
each owner's consent, and an owner consents to the scopes its `scopes:`
lists, which the consent page asks for. Each operation of the provider's
package names the scope it needs, `scope:`. A call to an operation outside
those scopes would be refused by the provider with every grant the
connection holds, so `jadpo check` says so where the call is written.

Jadpo won't add the scope for you. A new scope asks every owner for more
than they agreed to, the next time each connects, so it is your decision.

## What it looks like










```jadpo
use accounts/entities { User }

application {
    connections: {
        calendar: {
            package: GoogleCalendar.v3
            domains: [accounts]
            environment: config.calendar_environment
            credential: OAuthGrant {
                owner: User
                client_id: config.google_client_id
                client_secret: config.google_client_secret
                scopes: ["https://www.googleapis.com/auth/calendar.events"]
                return_to: "/settings/integrations"
            }
        }
    }
    grants: {
        encryption_key: config.grant_encryption_key
    }
}

principal {
    user: {
        subject: User.email
    }
}
```

The `accounts` domain reads the user's next events, which need the
`calendar.readonly` scope the connection doesn't ask for.

domains/accounts/actions/next_events.jadpo:

```jadpo
use app { calendar }
use shared/providers/google_calendar

/// The signed-in user's next events.
action next_events(me: Principal.user) -> GoogleCalendar.Upcoming {
    return calendar.events.upcoming(on_behalf_of: me.id)
}
```

```text
error: `calendar.events.upcoming` needs the scope `https://www.googleapis.com/auth/calendar.readonly`, which `calendar` doesn't ask for
 --> domains/accounts/actions/next_events.jadpo:6:12
  |
6 |     return calendar.events.upcoming(on_behalf_of: me.id)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^ needs `https://www.googleapis.com/auth/calendar.readonly`
  reason: An owner's grant allows only the scopes they consented to, which are the connection's `scopes:`, `https://www.googleapis.com/auth/calendar.events`; the provider would refuse this call with every grant `calendar` holds.
  next: Add `"https://www.googleapis.com/auth/calendar.readonly"` to `calendar`'s `scopes:` in `app.jadpo`, which asks every owner for it when they next connect, or call an operation those scopes allow (human)
  rule: connection.scope_not_requested
  help: https://jadpo.dev/docs/errors/connection.scope_not_requested

check failed: 1 error, 11 files
```

`(human)` at the end of the `next:` line tells your coding agent to stop
and ask you which fix you want, because the choice is yours to make: it
decides what every user is asked to allow when they connect.

## How to fix it

**If the app should read users' calendars**, add the scope to the
connection's `scopes:` in `app.jadpo`:

```diff
-                scopes: ["https://www.googleapis.com/auth/calendar.events"]
+                scopes: [
+                    "https://www.googleapis.com/auth/calendar.events"
+                    "https://www.googleapis.com/auth/calendar.readonly"
+                ]
```

Calling with a grant isn't built yet, so for now this call is `toolchain.not_built_yet`.

The consent page then asks each user for it too. A user who connected
before has a grant without it until they connect again.

**If it shouldn't**, leave the call out of `next_events`, or call an
operation the connection's scopes already allow:

```diff
-    return calendar.events.upcoming(on_behalf_of: me.id)
```

The app then asks no user for more than adding events to their calendar.

## Related

- [OAuth grants](/docs/oauth-grants.md)
- [Calling with a grant](/docs/oauth-grants.md#calling-with-a-grant)
- [`connection.on_behalf_of_missing`](/docs/errors/connection.on_behalf_of_missing.md)
