Skip to content

Instantly share code, notes, and snippets.

@jhliberty
Created June 12, 2015 03:21
Show Gist options
  • Save jhliberty/d8810b84dd91237db15b to your computer and use it in GitHub Desktop.
Save jhliberty/d8810b84dd91237db15b to your computer and use it in GitHub Desktop.
Basic JWT Auth for Seeds.js/Sane Stack (aka Ember on Sails)
var ENV = {
modulePrefix: 'frontend',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
'simple-auth': {
authorizer: 'simple-auth-authorizer:token',
serverTokenRevocationEndpoint: '/revoke',
crossOriginWhitelist: ['http://localhost:1776'],
routeAfterAuthentication: '/',
store: 'simple-auth-session-store:local-storage'
},
'simple-auth-token': {
serverTokenEndpoint: 'http://localhost:1776/login',
identificationField: 'email'
},
contentSecurityPolicy: {
'default-src': "'none'",
'script-src': "'self' 'unsafe-inline' 'unsafe-eval' http://cdnjs.cloudflare.com/",
'font-src': "'self' https://fonts.gstatic.com data:",
'connect-src': "'self' http://localhost:1776 http://localhost:3000",
'img-src': "'self' www.gravatar.com",
'report-uri':"'localhost'",
'style-src': "'self' 'unsafe-inline' https://fonts.googleapis.com http://cdnjs.cloudflare.com",
'frame-src': "'none'",
'media-src': "'self'"
}
}
// app/controllers/login.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
authenticate: function() {
var credentials = this.getProperties('identification', 'password'),
authenticator = 'simple-auth-authenticator:token';
this.get('session').authenticate(authenticator, credentials);
}
}
});
import Ember from "ember";
Router.map(function() {
this.route('login');
});
export default Router;
import Ember from "ember";
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(UnauthenticatedRouteMixin, {
});
<div class='ui row'>
<div class='ui segment'>
<div class="ui middle aligned center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="assets/logo.png" class="image">
<div class="content">
Log-in to your account
</div>
</h2>
<form class="ui large form" {{action 'authenticate' on='submit'}} >
<div class="ui stacked segment">
<div class="field">
<div class="ui left icon input">
<i class="user icon"></i>
{{input type="email" id='identification' placeholder='Enter Email' value=identification}}
</div>
</div>
<div class="field">
<div class="ui left icon input">
<i class="lock icon"></i>
{{input type="password" id='password' placeholder='Password' value=password}}
</div>
</div>
<button class="ui fluid large teal submit button" type="submit">Login</button>
</div>
<div class="ui error message"></div>
</form>
<div class="ui message">
Not a member yet? {{link-to 'Sign Up' 'signup'}}
</div>
</div>
</div>
</div>
</div>
{
"devDependencies": {
"ember-cli-seeds-scaffold": "1.0.4",
"ember-cli-simple-auth": "0.8.0-beta.2",
"ember-cli-simple-auth-token": "0.7.2",
}
}
module.exports.cors = {
allRoutes: true,
origin: 'http://localhost:4200',
headers: 'content-type, Authorization'
};
{
"sails-hook-jwt-auth": "^1.0.2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment