Skip to content

Commit

Permalink
Switch Beam to Mixer (#18)
Browse files Browse the repository at this point in the history
* Swap beam to mixer

* Reduce scopes slightly
  • Loading branch information
ProbablePrime authored and lipp committed Jul 3, 2017
1 parent 91d1597 commit 654f2cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Stateless authentication microservice for "login-with" functionality, supporting
- Reddit
- Facebook
- Google
- Beam
- Mixer
- ... more to come (PRs welcome)

You can deploy with `now` or `Docker` (for mandatory and optional env variables see below).
Expand Down Expand Up @@ -96,13 +96,13 @@ must be: `https://login.yourdomain.com/twitter/callback`
- `LW_TWITTER_CONSUMERKEY` - Your Twitter Consumer Key
- `LW_TWITTER_CONSUMERSECRET` - Your Twitter Consumer Secret

## Beam specific environment variables
## Mixer specific environment variables

You need to create your own Beam OAuth Client. If `LW_SUBDOMAIN=login.yourdomain.com` your Authorization callback URL
must be: `https://login.yourdomain.com/beam/callback`
You need to create your own Mixer OAuth Client. If `LW_SUBDOMAIN=login.yourdomain.com` your Authorization callback URL
must be: `https://login.yourdomain.com/mixer/callback`

- `LW_BEAM_CLIENTID` - Your Beam Client ID
- `LW_BEAM_CLIENT_SECRET` - Your Beam Client Secret
- `LW_MIXER_CLIENTID` - Your Mixer Client ID
- `LW_MIXER_CLIENTSECRET` - Your Mixer Client Secret


# Endpoints
Expand All @@ -112,7 +112,7 @@ must be: `https://login.yourdomain.com/beam/callback`
- `/github` - login with GitHub account (if configured through env variables)
- `/google` - login with Google account (if configured through env variables)
- `/reddit` - login with Reddit account (if configured through env variables)
- `/beam` - login with Beam account (if configured through env variables)
- `/mixer` - login with Mixer account (if configured through env variables)
- `/logout` - logout and clears the respective cookies

All endpoints expect the query parameters:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"express-session": "^1.14.2",
"jsonwebtoken": "^7.2.1",
"passport": "^0.3.2",
"passport-beam": "^1.0.4",
"passport-facebook": "^2.1.1",
"passport-github2": "^0.1.10",
"passport-google-oauth20": "^1.0.0",
"passport-mixer": "^1.0.1",
"passport-reddit": "^0.2.4",
"passport-strategy": "^1.0.0",
"passport-twitter": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const strategies = {
facebook: require('./facebook'),
reddit: require('./reddit'),
twitter: require('./twitter'),
beam: require('./beam'),
mixer: require('./mixer'),
test: require('./test')
}

Expand Down
17 changes: 7 additions & 10 deletions src/strategies/beam.js → src/strategies/mixer.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
module.exports = {
Ctor: require('passport-beam').Strategy,
Ctor: require('passport-mixer').Strategy,
getConfig: (env, callbackURL) => {
const clientID = env.LW_BEAM_CLIENTID
const clientSecret = env.LW_BEAM_CLIENTSECRET
const clientID = env.LW_MIXER_CLIENTID
const clientSecret = env.LW_MIXER_CLIENTSECRET
if (clientID && clientSecret) {
return {
clientID,
clientSecret,
callbackURL
callbackURL,
scope: ['channel:details:self']
}
}
},
toUser: (accessToken, refreshToken, profile, done) => {
let avatar
try {
avatar = JSON.parse(profile._raw).avatarUrl
} catch (error) {}
done(null, {
accessToken,
refreshToken,
profile: {
username: profile.username,
photo: avatar,
provider: 'beam'
photo: profile._raw.avatarUrl,
provider: 'mixer'
}
})
}
Expand Down
23 changes: 12 additions & 11 deletions test/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const test = require('../src/strategies/test')
const reddit = require('../src/strategies/reddit')
const twitter = require('../src/strategies/twitter')
const facebook = require('../src/strategies/facebook')
const beam = require('../src/strategies/beam')
const mixer = require('../src/strategies/mixer')
const assert = require('assert')

describe('the strategies module', () => {
Expand Down Expand Up @@ -377,43 +377,44 @@ describe('the strategies module', () => {
})
})

describe('beam', () => {
describe('mixer', () => {
let strategies
before(() => {
const env = {}
env.LW_BEAM_CLIENTID = 123
env.LW_BEAM_CLIENTSECRET = 432
env.LW_MIXER_CLIENTID = 123
env.LW_MIXER_CLIENTSECRET = 432
strategies = load(env, rootUrl)
})

it('gets loaded', () => {
assert.equal(strategies.length, 1)
assert.equal(strategies[0].type, 'beam')
assert.equal(strategies[0].type, 'mixer')
})

it('config is correct', () => {
assert.deepEqual(strategies[0].config, {
clientID: 123,
clientSecret: 432,
callbackURL: 'https://foo.bar/beam/callback'
scope: ['channel:details:self'],
callbackURL: 'https://foo.bar/mixer/callback'
})
})

it('toUser', done => {
const beamInfo = {
const mixerInfo = {
username: 'pop',
_raw: JSON.stringify({
_raw: {
avatarUrl: 'asd'
})
}
}
beam.toUser(123, 345, beamInfo, (error, user) => {
mixer.toUser(123, 345, mixerInfo, (error, user) => {
assert(!error)
assert.equal(user.accessToken, 123)
assert.equal(user.refreshToken, 345)
assert.deepEqual(user.profile, {
username: 'pop',
photo: 'asd',
provider: 'beam'
provider: 'mixer'
})
done()
})
Expand Down

0 comments on commit 654f2cc

Please sign in to comment.