How get token from a json link as variable?


try to build simple login form (see below).I need to send a request (token/new). From thats request i need the request_token as a variable so i can use it in the token/validate_with_login and that returning a token that is needed for the next session/new request. Someone suggestions how to build something like that in my controller?

App.AccountController = Ember.ObjectController.extend({
  actions: {
    userLogin: function(user) {
      	var keyapi = '000';

keyapi +"",function(){ alert ("" + this.getProperties.request_token + “”) });


keyapi + “&request_token=” + token + “&username=” + user.username + “&password=” + user.password + “”, function() {


keyapi + “&request_token=” + token + “”); self.transitionToRoute(‘settings’); }); }
} });


Hey Maartenheideman. I’m not sure if this is exactly what you’re looking for, but I am using queryParams. You might need to use a beta version of Ember, but I’m not sure if it has been put into the prod version yet. The way it works is if you have, then you can grab the “token” variable like I did below. It’s been working great.

App.NewPasswordController = Ember.ObjectController.extend Ember.Validations.Mixin,
  queryParams: ['token']
  token: null
    submit: ->
      token = @get 'token'
      password = @get 'password'
      passwordConfirmation = @get 'passwordConfirmation'

      data = password: password, password_confirmation: passwordConfirmation, token: token

      ic.ajax.request(type: 'PUT', url: 'api/v1/password_resets/update', data: JSON.stringify data).then (result)=>
        password: @get 'password'


hy @sturoid ,

Thanx for your suggestion. This is not what helps me, because i need a token that’s in a json file. So I need a controller that’s make a .getJSON call and from that call it must resturn a value ass variable (token variable) that i can use in a next .get call


Ah sorry I didn’t catch that. I don’t think that should be too difficult. One thing that helps a lot when dealing with ajax in Ember is to use something like ic-ajax. It takes care of all the promise expectations that Ember has. That will help with of a lot of problems you might run into. Especially when testing.


Is this helpful?

Maybe unrelated but, the “Query Params” way is the slickest way to do token auth, especially backed by JWT.