# Microsoft.Owin

**Kind:** Service

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

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

NuGet package dependency

`Microsoft.Owin` is a NuGet dependency in `Pams.Security` that supplies OWIN interfaces and request-pipeline types for .NET middleware. It lets security components read the OWIN request context, apply authentication behavior, and pass control to the next middleware component.

## Diagram

```mermaid
sequenceDiagram
    participant Client
    participant App as Pams Application
    participant Owin as Microsoft.Owin Pipeline
    participant Security as Pams.Security Middleware
    participant Endpoint

    Client->>App: HTTP request
    App->>Owin: Create OWIN context
    Owin->>Security: Invoke middleware
    Security->>Security: Read identity and request data
    Security->>Endpoint: Continue request pipeline
    Endpoint-->>Owin: Response
    Owin-->>Client: HTTP response
```

## Usage

```ts
type SessionResponse = {
  authenticated: boolean;
  userName?: string;
};

async function getCurrentSession(): Promise<SessionResponse> {
  const response = await fetch("/api/session", {
    credentials: "include",
    headers: {
      Accept: "application/json",
    },
  });

  if (!response.ok) {
    throw new Error(`Session request failed: ${response.status}`);
  }

  return response.json();
}

const session = await getCurrentSession();

if (session.authenticated) {
  console.log(`Signed in as ${session.userName}`);
} else {
  console.log("No authenticated OWIN session");
}
```

## AI Coding Instructions

- Keep OWIN-specific code within the .NET security and middleware layers; browser code should call endpoints exposed by the application.
- Pass authentication state through the OWIN context instead of creating parallel request-scoped identity objects.
- Preserve middleware ordering because authentication middleware must run before endpoints that require an authenticated user.
- Check the project’s existing NuGet package configuration before changing `Microsoft.Owin` references in the legacy-format project file.
