Skip to content

Commit

Permalink
More cleanup/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaccetti committed Apr 13, 2018
1 parent b40d81f commit 0643652
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ deploy:
- provider: releases
api_key:
secure: Ak2rWnFO5Hlu5Va5btfau1jZGYmfIyPrvaWO3rh/CphxkM7wv9cmYy5pFtWbyFLaEY0uiCV4B+gT1G5rcjiYqrzgQ9FFHBy2J2MsUTvaVzCUXGPFr6razkDDUsEf8fv+LMnjsS0V29ElTS7/46XCRsHPr3z+t4fdXCEQPmcHmc2uaL7rDsECNnxmkEEffMyF+at/Rvz5xXAr7btLalbnaEBpSMWCZWjiPtdKjSZXXJnnQ2vgqCYBNrVz706JxtFfQAj86TiBPR6TFELxZpdrgT4oper47QQTNiMgRJA6VUbeTvkgivNjNF61eAFrojkgwORJKhpg5mUEu4f0T/RSsmJf9oOg+fvA/V0jczjE8R99ILmPX2cTL12+V2AiXPeUH9+fsKVVC2IYyMGwLhDbwE6TQzV1gdjwhBSnfeF6Cz6rqJqP0ePAn/s3ndrVLUKpc+DHPTbEvZlXO5F82J0WaaC16T6SDI9+iN/j7mrpa7xLTmTmx+xlZPSUaCXuyiGUt3xgr10DyiwmmcuhPgmzUDMfaNU534uMXs17096i12tV5VHKSZaHcdCw0ai+VCMRViq7Bk2c5od5oIowCuCpwtxyOun0aqt2AKxHihkEhrb94SQmXMIM5ZJkruFD7FOgmA7hUN4SDlNU8EqLNF4876hrlL1IBaf5cF5MeOX2JtY=
file: release/ravel-steam-openid-provider.tgz
on:
repo: raveljs/ravel-steam-auth-provider
tags: true
Expand Down
51 changes: 34 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

> Ravel Authorization Provider for Steam
**Note:** This module is currently untested.

## Example usage:

*app.js*
```javascript
const Ravel = require('ravel');
const RavelSteamOpenIdProvider = require('@ravelravel-steam-auth-provider');
const RavelSteamOpenIdProvider = require('@ravel\ravel-steam-auh-provider');

const app = new Ravel();
new RavelSteamOpenIdProvider(app); // eslint-disable-line no-new
Expand Down Expand Up @@ -48,27 +46,46 @@ const Module = Ravel.Module;
const authconfig = Module.authconfig;

@authconfig
@inject('user-profiles')
@inject('service.user-service')
class AuthConfig extends Module {
constructor(userProfiles) {
this.userProfiles = userProfiles;
constructor (userProvider) {
super();
this.userProvider = userProvider;
}
serializeUser(profile) {

serializeUser (profile) {
// serialize profile to session using the id field
return Promise.resolve(profile.id);
this.log.debug(`Serializing ${JSON.stringify(profile)} to session.`);
return Promise.resolve(profile);
}
deserializeUser(id) {

deserializeUser (profile) {
// retrieve profile from database using id from session
return this.userProfiles.getProfile(id);
this.log.debug(`Retrieving user from DB using ${profile.id}`);
return this.userProvider.getProfile(profile.id);
}
verify(providerName, ...args) {
if (providerName === 'google-oauth2-web') {
const accessToken = args[0];
const refreshToken = args[1];
const profile = args[2];
// TODO something more complex, such as using/storing tokens
return Promise.resolve(profile);

async verify (providerName, ...args) {
this.log.debug(`Steam verify invoked for ${providerName}.`);
if (providerName === 'steam-auth-web') {
const profile = args[1];

this.log.debug(`Verifying user with profile ${JSON.stringify(profile)}`);

let user = null;
const userExists = await this.userProvider.profileExists(profile.id);
if (userExists === false) {
this.log.debug('User does not exist, creating.');
user = await this.userProvider.createProfile(profile);
} else {
this.log.debug('User exists, retrieving from DB.');
user = await this.userProvider.getProfileBySteamId(profile.id);
}

this.log.debug(`User from DB: ${JSON.stringify(user)}`);
return Promise.resolve(user);
}
return Promise.reject(new Error(`Unsupported authentication provider (${providerName}) used.`));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ravel-steam-auth-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SteamOpenIdProvider extends Ravel.AuthenticationProvider {
}

get name () {
return 'steam-openid-web';
return 'steam-auth-web';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.24.1",
"version": "0.24.2",
"name": "@ravel/ravel-steam-auth-provider",
"author": "Michael Laccetti <michael@laccetti.com> (https://laccetti.com/)",
"description": "Steam Auth Provider for Ravel Rapid Application Development Framework",
Expand Down

0 comments on commit 0643652

Please sign in to comment.