Last active
July 21, 2017 16:14
-
-
Save kturney/e54fdb91fca01e21deed7475664d913c to your computer and use it in GitHub Desktop.
ember-simple-auth setup for username/password cookie auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
/** | |
Ember CLI sends analytics information by default. The data is completely | |
anonymous, but there are times when you might want to disable this behavior. | |
Setting `disableAnalytics` to true will prevent any data from being sent. | |
*/ | |
"disableAnalytics": false, | |
// Use SSL for development server by default | |
"ssl": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; | |
import fetch from 'fetch'; | |
import Ember from 'ember'; | |
const { | |
RSVP | |
} = Ember; | |
const checkStatus = (response) => { | |
if (response.status >= 200 && response.status < 300) { | |
return response | |
} | |
const error = new Error(response.statusText) | |
error.response = response | |
error.statusCode = response.status; | |
throw error | |
}; | |
const parseJSON = (response) => { | |
return response.json() | |
}; | |
export default BaseAuthenticator.extend({ | |
authenticate(username, password) { | |
const req = { | |
method: 'POST', | |
credentials: 'same-origin', | |
headers: { | |
'accept': 'application/json', | |
'content-type': 'application/json' | |
}, | |
body: JSON.stringify({ username, password }) | |
}; | |
return fetch('/api/v1/sessions', req) | |
.then(checkStatus) | |
.then(parseJSON) | |
.then((newSession) => newSession.session); | |
}, | |
invalidate() { | |
const req = { | |
method: 'DELETE', | |
credentials: 'same-origin' | |
}; | |
return fetch('/api/v1/sessions/_current', req) | |
.then(checkStatus); | |
}, | |
restore(data) { | |
if (data) { | |
return RSVP.resolve(data); | |
} | |
return RSVP.reject(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { task } from 'ember-concurrency'; | |
const { | |
Component, | |
get, | |
getProperties, | |
inject | |
} = Ember; | |
const noop = () => {}; | |
export default Component.extend({ | |
session: inject.service(), | |
classNames: [ 'login-form' ], | |
tagName: 'form', | |
username: null, | |
password: null, | |
submit(ev) { | |
ev.preventDefault(); | |
get(this, 'authenticateTask').perform().catch(noop); | |
}, | |
authenticateTask: task(function * () { | |
const { username, password } = getProperties(this, 'username', 'password'); | |
yield get(this, 'session').authenticate('authenticator:basic', username, password); | |
}).drop() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; | |
const { | |
Route | |
} = Ember; | |
export default Route.extend(ApplicationRouteMixin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; | |
const { | |
get, | |
inject, | |
Route | |
} = Ember; | |
export default Route.extend(AuthenticatedRouteMixin, { | |
session: inject.service('session'), | |
store: inject.service('store'), | |
model() { | |
const userId = get(this, 'session.data.authenticated.id'); | |
return get(this, 'store').findRecord('employee', userId); | |
}, | |
afterModel(employee) { | |
// make sure venue and comapny are loaded | |
return get(employee, 'venue') | |
.then(() => get(employee, 'venue.company')); | |
}, | |
actions: { | |
error(error /* , transition */) { | |
if (get(error, 'errors.0.status') === '401') { | |
return get(this, 'session').invalidate(); | |
} | |
return true; | |
}, | |
logout() { | |
return get(this, 'session').invalidate(); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; | |
const { | |
Route | |
} = Ember; | |
export default Route.extend(UnauthenticatedRouteMixin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env node */ | |
'use strict'; | |
module.exports = function(environment) { | |
let ENV = { | |
modulePrefix: 'ven-u', | |
environment, | |
rootURL: '/', | |
locationType: 'auto', | |
EmberENV: { | |
FEATURES: { | |
// Here you can enable experimental features on an ember canary build | |
// e.g. 'with-controller': true | |
}, | |
EXTEND_PROTOTYPES: { | |
// Prevent Ember Data from overriding Date.parse. | |
Date: false | |
} | |
}, | |
APP: { | |
defaultRoute: 'venue' | |
}, | |
'ember-simple-auth': { | |
routeAfterAuthentication: 'venue', | |
routeIfAlreadyAuthenticated: 'venue' | |
} | |
}; | |
if (environment === 'development') { | |
// ENV.APP.LOG_RESOLVER = true; | |
// ENV.APP.LOG_ACTIVE_GENERATION = true; | |
// ENV.APP.LOG_TRANSITIONS = true; | |
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true; | |
// ENV.APP.LOG_VIEW_LOOKUPS = true; | |
} | |
if (environment === 'test') { | |
// Testem prefers this... | |
ENV.locationType = 'none'; | |
// keep test console output quieter | |
ENV.APP.LOG_ACTIVE_GENERATION = false; | |
ENV.APP.LOG_VIEW_LOOKUPS = false; | |
ENV.APP.rootElement = '#ember-testing'; | |
ENV['ember-tether'] = { | |
bodyElementId: 'ember-testing' | |
}; | |
} | |
// if (environment === 'production') { | |
// } | |
return ENV; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE----- | |
MIIDHjCCAgYCCQCZGYg+8G4RDjANBgkqhkiG9w0BAQsFADBRMQswCQYDVQQGEwJV | |
UzEOMAwGA1UECBMFVGV4YXMxDzANBgNVBAcTBkRhbGxhczEhMB8GA1UEChMYSW50 | |
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMB4XDTE3MDcwODIyNDAxOVoXDTE4MDcwODIy | |
NDAxOVowUTELMAkGA1UEBhMCVVMxDjAMBgNVBAgTBVRleGFzMQ8wDQYDVQQHEwZE | |
YWxsYXMxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJ | |
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTXUmCaR2rSPjCOH0s661wUjh/fyrUi | |
6qXhoZfX3McHPLDSByudNmziU/docxIvJc/DSPjqR/XIK+/xMxysyI3/aW1qM3tl | |
ma0mC/9HtqhxU8g6mu93v/keIOmyzA7CVgP/e8fnqtjErW2iR5Z7KNlugxcT94oc | |
NYaygAYznw8yuM7A02NpOoaIjqhUTXDHssOVj9Z9GIXYyzy9YtYS/dAq0HUEDm7X | |
MEt/WNIn6BBAefc+t+pjkCXNmEFjgW47vx6NCPeYnP6jMyDG6Brdozbqn27PK9IF | |
yMfHNvnEVYCIthgKUlxm8vRWOuE761XfCQuHxBug21Ng/UsrmImPe6UCAwEAATAN | |
BgkqhkiG9w0BAQsFAAOCAQEAC+yU73fOUqDYH83udTNfP5NDg0ypHRkbd/TY5QQi | |
oLTt8twXeOGolHbGd1vH0HsvhgsSTbG1YwozbEoIUdWoCGclSRYCMcoMmEgDaiqt | |
qWoITo17iOwQ1ywjC2wjRS3k6pK6gWyNX5aw2p7+Y50lU30g/1nN47fpJsQ5ACAB | |
L8uYx2/hXP2dzigcuRPPnPj7PtQCagCBTIuApREe183oS9bekKr+S5k0o7PICaJW | |
COvVeHKSMuYBGbo5dhxfzjhpNyKIq3kopJhcZ9m6Sgcyp7qtnwnp3Eqg5ONLO0x9 | |
pfPiG3HUDKlXJxe9x3NN9DxGQ9RzBWSgwdP1Nb4Pe1612w== | |
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE REQUEST----- | |
MIICljCCAX4CAQAwUTELMAkGA1UEBhMCVVMxDjAMBgNVBAgTBVRleGFzMQ8wDQYD | |
VQQHEwZEYWxsYXMxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCC | |
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTXUmCaR2rSPjCOH0s661wU | |
jh/fyrUi6qXhoZfX3McHPLDSByudNmziU/docxIvJc/DSPjqR/XIK+/xMxysyI3/ | |
aW1qM3tlma0mC/9HtqhxU8g6mu93v/keIOmyzA7CVgP/e8fnqtjErW2iR5Z7KNlu | |
gxcT94ocNYaygAYznw8yuM7A02NpOoaIjqhUTXDHssOVj9Z9GIXYyzy9YtYS/dAq | |
0HUEDm7XMEt/WNIn6BBAefc+t+pjkCXNmEFjgW47vx6NCPeYnP6jMyDG6Brdozbq | |
n27PK9IFyMfHNvnEVYCIthgKUlxm8vRWOuE761XfCQuHxBug21Ng/UsrmImPe6UC | |
AwEAAaAAMA0GCSqGSIb3DQEBBQUAA4IBAQBXMejwI/QE1yWYY/kobGu1Dls1NcVY | |
/lqmKARQ5ZBpFXNQ5b8Xo/BdvIoE9Y43KJg1XjSZrFIh6IppWpJb8mDmWIj2lCY0 | |
GMI8TN/tX4HtbopN9nNINzkRTXKzrba10o3nVjaQMQcOfmqca/lZ6GPnXtjiiKRQ | |
Gd89p4p0gEWHnkshzAFMS0K0Y7uw5INIOYDPD/3B+r0MR/r5WZM/LVhJSzNn3mcd | |
PNCtc2JCe2xZ7Zxd9maiI5M1YpwCZrMOQPVK20K5L/QF4ydvq9CWew7R+rCM7pRU | |
vaL8zJcPVC7tSCVbCXmJ1u1VdQ3VSV5VXbf0pFrc044g0euerZgkXcIx | |
-----END CERTIFICATE REQUEST----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN RSA PRIVATE KEY----- | |
MIIEpAIBAAKC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KKxcyUfoMCgYEAzfIjWmfnKDn4iCO8arSc | |
AKN0ENl6HC/X5m71sA05jWhvKS9mhdYnY1KRXczQY+IQShpcz5uE6JXtghJlZadD | |
Fm2l7VN9/DygCAEVFKnfPG5sUqnuVBJ+fqS3bHL8ONbzrck6uWKJED9cWYMDkd8J | |
XIutf7/hFm2HwkzIA7VtRHsCgYA1o/0E8+i5AL41+KBVQP4lAXCpQ1PFjfJM8yCZ | |
o4MJsu8QT/51G93Ls+geZep0wTfS06OxZcMXSp6shpAmcTootYR/PqUlNnhg/Evy | |
mw35lP1oyxgHO+21ENZx/E3hWoO9Iby1NoDp0Us5OI10PWJULEjSaMcesW0pB0+Z | |
PYFVDwKBgQDYmj4MSNLJiHVNxMMwG9qCAuLP/SldWlavdmbJ9qRLqE/gBnpDrnb6 | |
/o5Z1DxEK+cmaNWQ8HBaDqqoUuODGll8YzXFdPXLl7ng6DY7nsmOc1MVd1qpTfWF | |
4rOCQB67We9QUhaR4MGWcqMeNayi38rK9A90z/6tt47uXTwFi+xgiQ== | |
-----END RSA PRIVATE KEY----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment