> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/fastapi/fastapi/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenID Connect

> OpenID Connect authentication for FastAPI

## OpenIdConnect

OpenID Connect authentication class. An instance of it would be used as a dependency.

**Warning:** this is only a stub to connect the components with OpenAPI in FastAPI, but it doesn't implement the full OpenIdConnect scheme, for example, it doesn't use the OpenIDConnect URL. You would need to to subclass it and implement it in your code.

### Parameters

<ParamField path="openIdConnectUrl" type="str" required>
  The OpenID Connect URL.
</ParamField>

<ParamField path="scheme_name" type="str | None" default="None">
  Security scheme name. It will be included in the generated OpenAPI (e.g. visible at `/docs`).
</ParamField>

<ParamField path="description" type="str | None" default="None">
  Security scheme description. It will be included in the generated OpenAPI (e.g. visible at `/docs`).
</ParamField>

<ParamField path="auto_error" type="bool" default="True">
  By default, if no HTTP Authorization header is provided, required for OpenID Connect authentication, it will automatically cancel the request and send the client an error.

  If `auto_error` is set to `False`, when the HTTP Authorization header is not available, instead of erroring out, the dependency result will be `None`.

  This is useful when you want to have optional authentication or when you want to have authentication that can be provided in one of multiple optional ways (for example, with OpenID Connect or in a cookie).
</ParamField>

### Example

```python theme={null}
from fastapi import Depends, FastAPI
from fastapi.security import OpenIdConnect

app = FastAPI()

oidc_scheme = OpenIdConnect(openIdConnectUrl="https://example.com/.well-known/openid-configuration")

@app.get("/users/me")
async def read_current_user(token: str = Depends(oidc_scheme)):
    return {"token": token}
```
