Skip to content

Instantly share code, notes, and snippets.

@theotherdon
Created December 26, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theotherdon/2034d290b6344d89adba to your computer and use it in GitHub Desktop.
Save theotherdon/2034d290b6344d89adba to your computer and use it in GitHub Desktop.
Login a User programatically with ng-token-auth.
def login_user_programatically
# User or whatever the name of the model is that you're trying to authenticate
@request.env['devise.mapping'] = Devise.mappings[:user]
@resource = FactoryGirl.create(:confirmed_user)
# The following two lines are where the magic happens.
@auth_headers = @resource.create_new_auth_token
@request.headers.merge!(@auth_headers)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment