# OAuth2 Authentication

Type: `middleware.http.oauth2`

Status: alpha

Reference: https://docs.dapr.io/reference/components-reference/supported-middleware/middleware-oauth2/

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: middleware.http.oauth2
  version: v1
  metadata:
    # The OAuth2 authorization URL from your provider
    - name: authURL
      value: "https://accounts.google.com/o/oauth2/v2/auth"
    # The OAuth2 client ID from your OAuth2 provider
    - name: clientID
      value: "client-id"
    # The OAuth2 client secret from your OAuth2 provider
    - name: clientSecret
      value: "client-secret"
    # The OAuth2 token URL from your provider
    - name: tokenURL
      value: "https://oauth2.googleapis.com/token"
    # OAuth2 scopes to request from your provider (Optional)
    #- name: scopes
    #  value: "openid profile email"
    # The name of the authorization header to use (Optional)
    #- name: authHeaderName
    #  value: "Authorization"
    # Whether to force HTTPS for the redirect URL (Optional)
    #- name: forceHTTPS
    #  value: "false"
    # Regular expression to filter which paths require authentication (Optional)
    #- name: pathFilter
    #  value: "^/api/.*"
    # The OAuth2 redirect URL for your application (Optional)
    #- name: redirectURL
    #  value: "http://mycompany.com:8080/callback"

```

## Authentication profiles

Available authentication profiles:

- OAuth2 Authentication

### OAuth2 Authentication

Configure OAuth2 authentication with any OAuth2 provider

#### `authURL` (string)

**Required** - The OAuth2 authorization URL from your provider

Example value: `https://accounts.google.com/o/oauth2/v2/auth`

#### `clientID` (string)

**Required** - The OAuth2 client ID from your OAuth2 provider

Example value: `client-id`

#### `clientSecret` (string)

**Required** - The OAuth2 client secret from your OAuth2 provider

Example value: `client-secret`

#### `tokenURL` (string)

**Required** - The OAuth2 token URL from your provider

Example value: `https://oauth2.googleapis.com/token`

#### `scopes` (string)

OAuth2 scopes to request from your provider

Example value: `openid profile email`

## Metadata

### `authHeaderName` (string)

The name of the authorization header to use

Default value: `Authorization`

Example value: `Authorization`

### `forceHTTPS` (string)

Whether to force HTTPS for the redirect URL

Default value: `false`

Example value: `true`

### `pathFilter` (string)

Regular expression to filter which paths require authentication

Example value: `^/api/.*`

### `redirectURL` (string)

The OAuth2 redirect URL for your application

Example value: `http://mycompany.com:8080/callback`
