# remix-auth-steam

> This is a [Steam](https://steamcommunity.com/) strategy for [remix-auth](https://github.com/sergiodxa/remix-auth) library.

Latest version **1.0.4** (published 2022-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install remix-auth-steam
pnpm add remix-auth-steam
yarn add remix-auth-steam
bun add remix-auth-steam
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-01-08 |
| First published | 2022-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Andrii Yaroshenko |
| Maintainers | haxellio |
| Keywords | remix, remix-auth, auth, authentication, strategy, steam, remix-steam |

## Links

- npm: https://www.npmjs.com/package/remix-auth-steam
- Repository: https://github.com/Andreychik32/remix-auth-steam
- Homepage: https://github.com/Andreychik32/remix-auth-steam#readme
- Issues: https://github.com/Andreychik32/remix-auth-steam/issues
- npm.io page: https://npm.io/package/remix-auth-steam

## Dependencies (4)

- [openid](https://npm.io/package/openid.md) ^2.0.10
- [steamapi](https://npm.io/package/steamapi.md) ^2.2.0
- [remix-auth](https://npm.io/package/remix-auth.md) ^3.0.0
- [@types/steamapi](https://npm.io/package/@types/steamapi.md) ^2.2.2

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-01-08
- 1.0.3 — 2022-01-05
- 1.0.2 — 2022-01-05
- 1.0.1 — 2022-01-05

## README

# Remix Auth Steam Strategy

This is a [Steam](https://steamcommunity.com/) strategy for [remix-auth](https://github.com/sergiodxa/remix-auth) library.

## Supported runtimes

| Runtime    | Has Support         |
| ---------- | ------------------- |
| Node.js    | ✅                  |
| Cloudflare | Not tested          |

## How to use
### Installation

Please, use
```bash
npm i remix-auth-steam
```
or
```bash
yarn add remix-auth-steam
```


### File structure

To properly use the library, you need to maintain these additional files in your `app` directory:

`app/services/auth.server.ts`:
```ts
import { Authenticator } from "remix-auth";
import { sessionStorage } from "~/services/session.server";
import { SteamStrategy, SteamStrategyVerifyParams } from "remix-auth-steam";

export type User = SteamStrategyVerifyParams;

export let authenticator = new Authenticator<User>(sessionStorage);

authenticator.use(
  new SteamStrategy(
    {
      returnURL: "http://localhost:3000/auth/steam/callback",
      apiKey: "YOUR_STEAM_API_KEY", // you can get it here: https://steamcommunity.com/dev/apikey
    },
    async (user) => user // perform additional checks for user here, I just leave this to SteamStrategyVerifyParams value
  )
);
```

`app/services/session.server.ts`:
```ts
import { createCookieSessionStorage } from "remix";

const calculateExpirationDate = (days: number) => {
  const expDate = new Date()
  expDate.setDate(expDate.getDate() + days)
  return expDate
}

// export the whole sessionStorage object
export let sessionStorage = createCookieSessionStorage({
  cookie: {
    name: "_session", // use any name you want here
    sameSite: "lax", // this helps with CSRF
    path: "/", // remember to add this so the cookie will work in all routes
    httpOnly: true, // for security reasons, make this cookie http only
    secrets: ["s3cr3t"], // replace this with an actual secret
    secure: process.env.NODE_ENV === "production", // enable this in prod only
    expires: calculateExpirationDate(7) // expire cookie after 7 days
  },
});

// you can also export the methods individually for your own usage
export let { getSession, commitSession, destroySession } = sessionStorage;
```

`app/routes/auth/steam.tsx`:
```tsx
import { LoaderFunction } from "remix";
import { authenticator } from "~/services/auth.server";

export let loader: LoaderFunction = async ({ request }) => {
  await authenticator.authenticate('steam', request, {});
};
```

`app/routes/auth/steam/callback.tsx`:
```tsx
import { LoaderFunction } from 'remix'
import { authenticator } from '~/services/auth.server'

export let loader: LoaderFunction = ({ request }) => {
  return authenticator.authenticate('steam', request, {
    successRedirect: '/',
    failureRedirect: '/login',
  })
}
```

### Utilization

After that, navigate to `localhost:3000/auth/steam` to check if it works. Here is an example of checking if user is authenticated:
`app/routes/index.tsx`:
```tsx
import { LoaderFunction, useLoaderData } from "remix";
import { authenticator, User } from "~/services/auth.server";

export let loader: LoaderFunction = async ({ request }) => {
  const user = await authenticator.isAuthenticated(request)
  return user
}

export default function Index() {
  const user: User | null = useLoaderData()

  return (
    <div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
      {user ? <h1>User name: {user!.nickname}</h1> : <h1>Not authenticated</h1>}
    </div>
  );
}
```

If you are logged in, you should see your username from Steam API, otherwise you will see `Not authenticated` message.

# Contributing

Your contributions are highly appreciated! Please, submit any pull requests or issues you found!

---
_Source: https://npm.io/package/remix-auth-steam · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
