authentication - Ember simple-auth mixins deprected -


i experienced (55+ years) programmer total noob in ember , js. i'm trying simple authentication page working using ember-cli addons ember-cli-simple-auth, ember-cli-simple-auth-oauth2 , cut-and-paste simplelabs tutorial.

i following in console:

deprecation: logincontrollermixin deprecated. use session's authenticate method directly instead.

and:

deprecation: authenticationcontrollermixin deprecated. use session's authenticate method directly instead.

the solution may trivial, have been chasing hours , deep javascript before reaching dead-end. code causing these errors is:

import logincontrollermixin 'simple-auth/mixins/login-controller-mixin';

export default ember.controller.extend(logincontrollermixin, { authenticator: 'simple-auth-authenticator:oauth2-password-grant' });

which invokes applicationcontrollermixin somewhere in bower code.

before "re-invent wheel" translating old html/ruby/pascal code js, can me "use session's authenticate method directly instead."?

thanks.

i feel you're pain. spent weeks trying sort out. big part of problem has changed in past couple of years , there lot of code examples out there outdated or don't work together. it's difficult put various pieces coherently, , figure out 1 not need do.

that said, please keep in mind i'm n00b well. i've done seems work ok i've no idea whether there's better way.

also, you're trying may not same i've done. app authenticates against google (and twitter, fb, etc.) using simple-auth-torii , exchanges returned authenication code authentication token. last part happens on server. so, after session authenticates, pass auth code server , auth code.

// routes/login.js import ember "ember"; import env "../config/environment";  export default ember.route.extend({   setupcontroller: function(controller, model) {     controller.set("errormessage", null);   },    actions: {     googlelogin: function() {       var _this = this;        // using "session's authenticate method directly" right here        this.get("session").authenticate("simple-auth-authenticator:torii", "google-oauth2")         .then(function() {           // we're authenticated. session should contain authorization           // code provider. need exchange auth token.           var securedata = _this.get("session.content.secure");            // call server initiate token exchange provider           var exchangedata = {             authorizationcode: securedata.authorizationcode,             redirecturi    : securedata.redirecturi,             provider     : 'google'           };            // sends ajax request server, in turn call provider           // authentication code , receive auth token           _this.tokenservice.fetch(exchangedata).then(function(response) {              if (response.success) {               _this.set("session.content.secure.access_token", response.data.token);               _this.set("session.content.secure.userdata", response.data.user);                // take user somewhere ...               _this.transitionto("data_sets");             }             else {               // set error message, log response console, whatever,               // need invalidate session because far simple-auth               // concerned we're authenticated. following logs user out.               _this.get("session").invalidate();             }           }, function(error) {             console.log("tokenservice.fetch error", error);             _this.get("session").invalidate();           });          }, function(error) {           console.log("simple-auth-authenticator:torii error", error);           _this.get("session").invalidate();         });     },      twitterlogin: function() {       // etc.     }   } }); 

logging user out uses session directly.

{{!templates/application.hbs}} <ul class="nav navbar-nav navbar-right"> {{#if session.isauthenticated}}   <li><button {{ action 'invalidatesession' }} class="btn btn-sm">logout</button></li> {{/if}}   ... </ul>   // routes/application.js import ember "ember"; import env "../config/environment"; import applicationroutemixin "simple-auth/mixins/application-route-mixin";  export default ember.route.extend(applicationroutemixin, {    actions: {     // action globally available because in application route     invalidatesession: function() {       // basic logout       this.get("session").invalidate();       return;        // if need invalidate on server like:       //       // var _this = this;       // return new ember.rsvp.promise(function(resolve, reject) {       //   var params = {       //     url    : env.logoutendpoint,       //     type     : "post",       //     datatype   : "json"       //   };        //   ember.$.ajax(params).then(function(response) {       //     console.log('session invalidated!');       //     console.dir(response);       //     _this.get("session").invalidate();       //   });       // });     }   } }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -