私はAngularjs、Rails、devise_token_auth、およびng-token-authを使用しており、コンソールからユーザーにログインしようとしています。Devise Token Auth - Railsコンソールから保護されたルートにアクセスする方法
私は、Tim Santefordが投稿した30236を入手する方法を知らないので、this投稿に記載します。
これはRails 4にも適用できますか?それとも、200応答でもまだ正常にログインできなかったのですか?
私はBrian Deterlingで言及したPOSTリクエストを行うと、私が手:
Started POST "/api/private/auth/sign_in" for 127.0.0.1 at 2016-03-30 13:36:44 -0500
Processing by DeviseTokenAuth::SessionsController#create as JSON
Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]"}
...
(9.9ms) COMMIT
Completed 200 OK in 361ms (Views: 0.4ms | ActiveRecord: 23.3ms)
=> 200
私はティムSantefordが言及していること302応答の代わりに200を除いて正常に署名したようなので、それが見えます。
次に、私はapp.sessionを実行し、動作するように見えます。
irb(main):026:0> app.session
=> #<ActionDispatch::Request::Session:0x007fe7a1898358 @by=#<ActionDispatch::Session::CookieStore:0x007fe79ed821f0
...
@delegate={"session_id"=>"4346eb0ee9fc8a8e95735d1e3f2adc28"}, @loaded=true, @exists=true>
はその後、私はapp.controller.current_userを行うと、それはあまりにも動作するようにこれが見えます。
irb(main):027:0> app.controller.current_user
=> #<User id: 233, provider: "email", uid: "[email protected]", encrypted_password: "$2a$10$v2fapiZCH5b5XN.ji57KgOJ0SJfVHzJByYPFpVCeU1j...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 32, current_sign_in_at: "2016-03-30 18:36:44", last_sign_in_at: "2016-03-30 18:01:00", current_sign_in_ip: "127.0.0.1",
しかし、私は保護され、私は
irb(main):029:0> app.get('/api/private/rfqs')
Started GET "/api/private/rfqs" for 127.0.0.1 at 2016-03-30 14:11:21 -0500
Processing by Api::RfqsController#index as JSON
Filter chain halted as :authenticate_user! rendered or redirected
Completed 401 Unauthorized in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
=> 401
を取得...と、この要求の後、私は再び私は
取得app.sessionとapp.controller.current_userをすればルーティングを入力します。irb(main):030:0> app.session
=> #<ActionDispatch::Request::Session:0x7fe7a1213910 not yet loaded>
irb(main):031:0> app.controller.current_user
=> nil
なぜこのようなことが起こっているのか教えていただけますか?