GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Frozenfire92/EmberAuthTutorial: A quick Ember.js authorization tutorial (OLD NEEDS UPDATE)

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
app
app
 
 
config
config
 
 
public
public
 
 
tests
tests
 
 
vendor
vendor
 
 
.bowerrc
.bowerrc
 
 
.editorconfig
.editorconfig
 
 
.ember-cli
.ember-cli
 
 
.gitignore
.gitignore
 
 
.jshintrc
.jshintrc
 
 
.travis.yml
.travis.yml
 
 
Brocfile.js
Brocfile.js
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bower.json
bower.json
 
 
package.json
package.json
 
 
testem.json
testem.json
 
 

Repository files navigation

Ember-auth-tutorial

This is a tutorial outlining how to create an Ember.js app with authorization using

  • Ember-CLI
  • Ember-Simple-Auth
  • Torii

Tutorial

This assumes you have git, node, bower, and ember-cli installed

Create a new ember app

ember init or ember new see the ember-cli docs for more info

Get dependencies

npm install --save-dev torii ember-cli-simple-auth-torii
ember generate ember-cli-simple-auth-torii

Basic App setup

ember g route application
ember g route protected
ember g route login
ember g controller login

Add Mixins

//--- /app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin);
//--- /app/routes/protected.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin);

Add Login Actions and setup controller

You could add more torii providers, see the documentation for more info

//--- /app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export default Ember.Controller.extend(LoginControllerMixin, {
  authenticator: 'authenticator:torii'
});
//--- /app/routes/login.js
import Ember from 'ember';

export default Ember.Route.extend({
	actions: {
		googleLogin: function() {
			this.get('session').authenticate('simple-auth-authenticator:torii', 'google-oauth2');
			return;
		}
	}
});

Update your templates

See example

Get google setup

This is likely analgous to other torii providers, I have only used google

  • client_id from google under API & auth > credentials
  • update your authorized origins (ex. http://localhost:4200/)
  • update the redirect URI (ex. http://localhost:4200)

Update environment.js

//--- config/environment.js
ENV['torii'] = {
  providers: {
    'google-oauth2': {
      apiKey: 'client_id from google',
      scope: 'profile',
      redirectUri: 'http://localhost:4200'
    }
  }
};

Test & Enjoy

run ember server and try it out!

Bonus: Get user info from google

We are going to create a custom torii provider that will also get the users information from google. We need the custom provider because the default google-ouath2 uses the code workflow rather than the token workflow that the google plus api's need. This code extends torii oauth2-bearer and borrows from torri google-oauth2. It also uses jQuery for the GET request, if there is a better way let me know!

  • Custom Provider

Then update:

  • environment.js torii provider to match the custom providers name (this provider also uses scope profile email)
  • Your login action to match the custom providers name

Then enable the Google+ API in your google dev console

You now will have access to session.content.userName and session.content.userEmail

About

A quick Ember.js authorization tutorial (OLD NEEDS UPDATE)

frozenfire92.github.io/EmberAuthTutorial

Resources

Readme
Unlicense
Activity

Stars

23 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.