# Microsoft.Owin.Security.Facebook

**Kind:** Service

**Source:** `Pams/API/Pams.API/Pams.API.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`Microsoft.Owin.Security.Facebook` is a NuGet dependency in the Pams API project that adds Facebook authentication support to the OWIN security pipeline. The API can redirect users to Facebook for sign-in and process the callback to create an authenticated application session.

## Diagram

```mermaid
sequenceDiagram
    participant Client
    participant Api as Pams API
    participant Facebook

    Client->>Api: Request Facebook sign-in
    Api->>Facebook: Redirect to authorization endpoint
    Facebook->>Client: Request authentication and consent
    Client->>Facebook: Submit authentication result
    Facebook->>Api: Send authorization callback
    Api->>Facebook: Exchange callback for identity data
    Facebook-->>Api: Return authenticated identity
    Api-->>Client: Return application session response
```

## Usage

```ts
async function signInWithFacebook() {
  const response = await fetch("/api/auth/facebook", {
    method: "POST",
    credentials: "include",
  });

  if (!response.ok) {
    throw new Error("Facebook sign-in could not be started.");
  }

  const { redirectUrl } = await response.json();
  window.location.assign(redirectUrl);
}
```

## AI Coding Instructions

- Keep `Microsoft.Owin.Security.Facebook` configured in the OWIN authentication startup pipeline.
- Store Facebook application credentials in environment-specific configuration rather than source control.
- Match the Facebook callback URL with the redirect URI registered for the Facebook application.
- Handle authentication failures returned from the callback before creating an application session.

## Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Injected or called by (1)

- `Pams.API` — `Pams/API/Pams.API/Pams.API.csproj`:1
