61142

Ember-Simple-Auth with Torii access user info

Question:

I've been working all week to get authentication working. I have gotten it working with

<ul><li>Ember-CLI</li> <li>Ember-Simple-Auth</li> <li>Torii <ul><li>google-oauth2 provider</li> </ul></li> </ul>

However I have proven unsuccessful in getting the users information from google. I have tried creating a torii-adapter as stated in their documentation but it doesn't appear to be called

// app/torii-adapters/application.js export default Ember.Object.extend({ open: function(authorization){ console.log('authorization from adapter', authorization); } });

I've exhausted my google-foo and am asking for your assistance. This is a great library combination for authorization however the documentation is lacking for this case, and when figured out I will be sure to contribute back.

Thank you

Answer1:

The problem I was encountering is Torii's default google-oauth2 provider doesn't access this info for you, also it uses the code workflow instead of the token workflow which is needed for the google+ API

To fix this I wrote a custom provider that uses a jquery GET request to the G+ API, I then return the userName and userEmail to access it in the session under content.

I wrote a full tutorial detailing authorizing an ember app using google start to finish <a href="https://github.com/Frozenfire92/EmberAuthTutorial" rel="nofollow">here</a>

//app/torii-providers/google-token.js import {configurable} from 'torii/configuration'; import Oauth2Bearer from 'torii/providers/oauth2-bearer'; var GoogleToken = Oauth2Bearer.extend({ name: 'google-token', baseUrl: 'https://accounts.google.com/o/oauth2/auth', // additional params that this provider requires requiredUrlParams: ['state'], optionalUrlParams: ['scope', 'request_visible_actions', 'access_type'], requestVisibleActions: configurable('requestVisibleActions', ''), accessType: configurable('accessType', ''), responseParams: ['token'], scope: configurable('scope', 'email'), state: configurable('state', 'STATE'), redirectUri: configurable('redirectUri', 'http://localhost:8000/oauth2callback'), open: function(){ var name = this.get('name'), url = this.buildUrl(), redirectUri = this.get('redirectUri'), responseParams = this.get('responseParams'); var client_id = this.get('client_id'); return this.get('popup').open(url, responseParams).then(function(authData){ var missingResponseParams = []; responseParams.forEach(function(param){ if (authData[param] === undefined) { missingResponseParams.push(param); } }); if (missingResponseParams.length){ throw "The response from the provider is missing " + "these required response params: " + responseParams.join(', '); } return $.get("https://www.googleapis.com/plus/v1/people/me", {access_token: authData.token}).then(function(user){ return { userName: user.displayName, userEmail: user.emails[0].value, provider: name, redirectUri: redirectUri }; }); }); } }); export default GoogleToken;

Recommend

  • Reading text file in Matlab results in unknown spaces within characters
  • What is the proper way to handle menu items in a master/detail flow?
  • Java - add a button in a cell in a Jtable
  • How to compute daily average for 15 years?
  • Dilemma in deciding how to create CSS for H1, H2, H3 etc
  • How does Chrome get device orientation information?
  • Sorting an array of files for rename
  • Gradle Thrift Plugin by Example
  • Python: some “__magic__” attribute to reference a function from within that function
  • Is there a difference between initializing a variable in the default constructor or inline? [duplica
  • PHP: Calling a private method from within a class dying badly
  • Dynamically set LESS variables from user settings
  • if some function is not optimized does it mean that all functions where it is declared are not optim
  • Why does the following throw an “Object doesn't support property or method 'importNode
  • AWS-SES: Handling Bounces for Invalid ISPs
  • Why doesn't a local variable live long enough for thread::scoped?
  • Relative paths. baseUrl and paths not working on ionic2 - angular2
  • Django model for a Postgres view
  • How to retrieve information from antrun back to maven?
  • How to disable all widgets inside Panel or inside Composite?
  • SharedPreferences or SQLite Database?
  • PHP CURL timing out but CLI CURL works
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Meteor helpers not available in Angular template
  • swift auto completion not working in Xcode6-Beta
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • How to make Safari send if-modified-since header?
  • Build own AppleScript numerical error handling
  • ORA-29908: missing primary invocation for ancillary operator
  • Jquery - Jquery Wysiwyg return html as a string
  • Apache 2.4 - remove | delete | uninstall
  • How to pass list parameters for each object using Spring MVC?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • JaxB to read class hierarchy
  • Converting MP3 duration time
  • java string with new operator and a literal