Skip to content

Commit

Permalink
fix: update dependencies and chores (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
danocmx authored Jul 15, 2024
2 parents fecb02b + 8563675 commit 754a20f
Show file tree
Hide file tree
Showing 4 changed files with 2,001 additions and 2,400 deletions.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,56 @@ This package only relies on [passport](https://www.passportjs.org/) and [axios](

Library is fully covered with tests, both unit and integration tests to make sure everything runs correctly.

## API

Instantiate the `SteamOpenIdStrategy` as following:
```ts
new SteamOpenIdStrategy(options, verify)
```

Options object has the following properties:
- `returnURL` - URL to which steam will redirect user after authentication
- `profile` - If set to true, it will fetch user profile from steam api, otherwise only steamid will be returned
- `apiKey` - Steam api key, required if `options.profile` is set to true
- `maxNonceTimeDelay` - Optional, in seconds, time between creation and verification of nonce date, if not set no verification occurs.

Second parameter of `SteamOpenIdStrategy` is a callback function used for verifying logged in user, with the following parameters:
- `req` - Express request object
- `steamid` - Steam id of the authenticated user
- `profile` - Full profile from GetPlayerSummaries api, if `options.profile` is set to true, otherwise only steamid
- `done` - Passport callback function

Profile if `options.profile` is set to true:
```ts
export type SteamOpenIdUserProfile = {
steamid: string;
communityvisibilitystate: number;
profilestate: number;
personaname: string;
commentpermission: number;
profileurl: string;
avatar: string;
avatarmedium: string;
avatarfull: string;
avatarhash: string;
lastlogoff: number;
personastate: number;
realname: string;
primaryclanid: string;
timecreated: number;
personastateflags: number;
loccountrycode: string;
locstatecode: string;
};
```

Other it is just:
```ts
export type SteamOpenIdUser = {
steamid: string;
};
```

## Usage
```ts
import { SteamOpenIdStrategy } from 'passport-steam-openid';
Expand All @@ -13,11 +63,12 @@ passport.use(
new SteamOpenIdStrategy({
returnURL: 'http://localhost:3000/auth/steam',
profile: true,
apiKey: '<insert steam api key>'
apiKey: '<insert steam api key>', // No need for api key, if profile is set to false
maxNonceTimeDelay: 30 // Optional, in seconds, time between creation and verification of nonce date
}, (
req: Request,
identifier: string,
profile: SteamOpenIdUserProfile,
profile: SteamOpenIdUserProfile, // if profile is false, then it's only { steamid }, otherwise full profile from GetPlayerSummaries api
done: VerifyCallback
) => {
// Optional callback called only when successful authentication occurs
Expand All @@ -44,6 +95,8 @@ app.use(
// Steam rejected this authentication request
case SteamOpenIdErrorType.InvalidSteamId:
// Steam profile doesn't exist
case SteamOpenIdErrorType.NonceExpired:
// Nonce has expired, only if `options.maxNonceTimeDelay` is set
}
}
// ...
Expand All @@ -59,6 +112,7 @@ Install using npm:
```
npm install passport-steam-openid
```

Library's API has been unchanged and stable for some time now. It will not change unless a breaking change is issued by steam (very unlikely).

## License
Expand Down
Loading

0 comments on commit 754a20f

Please sign in to comment.