2016-11-18 90 views
0

Devise_auth_token新手在這裏。我有一個唯一的應用程序。我試圖用curl向我的api發出請求,除了當我想登錄一個用戶時,我已經成功地做到了這一點。devise_auth_token期待什麼參數?

curl -XPOST -H 'Content-Type: application/json' -d '{ "session": { "email":"[email protected]", "password": "password"}}' localhost:3000/auth/sign_in 

不知道我在做什麼錯。正如我所說,出於某種原因,創建用戶時沒有任何問題。當試圖登錄我得到這個錯誤

{"errors":["Invalid login credentials. Please try again."]} 

任何幫助非常感謝,謝謝。

+0

您是否檢查過您的rails日誌文件? – Eric

+0

@Eric開始POST「/ auth/sign_in」爲:: 1在2016-11-18 14:52:41 -0500 DeviseTokenAuth :: SessionsController處理#create as */* 參數:{「session」=> {「email」=>「[email protected]」,「password」=>「[FILTERED]」}} 未經許可的參數:session 已完成401 1ms內未授權(視圖:0.1ms | ActiveRecord:0.0ms) – RickD

+0

@ Eric是我提出的請求的記錄結果。 – RickD

回答

0
curl -v -XPOST -H 'Content-Type: application/json' -d '{ "email":"[email protected]", "password": "password"}' localhost:3000/auth/sign_in 
    * Hostname was NOT found in DNS cache 
    * Trying 127.0.0.1... 
    * Connected to localhost (127.0.0.1) port 3000 (#0) 
    > POST /auth/sign_in HTTP/1.1 
    > User-Agent: curl/7.35.0 
    > Host: localhost:3000 
    > Accept: */* 
    > Content-Type: application/json 
    > Content-Length: 55 
    > 
    * upload completely sent off: 55 out of 55 bytes 
    < HTTP/1.1 200 OK 
    < X-Frame-Options: SAMEORIGIN 
    < X-XSS-Protection: 1; mode=block 
    < X-Content-Type-Options: nosniff 
    < Content-Type: application/json; charset=utf-8 
    < access-token: Bm3FaRpSAjT-EtTrj8Ucww 
    < token-type: Bearer 
    < client: 6XCiYTxcEITVRZItRKFa8w 
    < expiry: 1480750998 
    < uid: [email protected] 
    < ETag: W/"be9091473a08ccf2672b9685eb25caa2" 
    < Cache-Control: max-age=0, private, must-revalidate 
    < X-Request-Id: 4996fb00-a45c-41e4-b30b-c86bc10b24d5 
    < X-Runtime: 0.737506 
    < Transfer-Encoding: chunked 
    < 
    * Connection #0 to host localhost left intact 
    {"data":{"id":1,"email":"[email protected]","provider":"email","uid":"[email protected]","name":null,"nickname":null,"image":null}} 

使用-v捲曲 - 它會給你很多線索。 評論是正確的 - 不要將登錄名/密碼放在session之內。

TL;DR剪斷,你應該仔細閱讀:

認證報頭由以下則params的:access-tokenclientexpireuid

爲每個請求將在提供所需的認證頭來自先前請求的響應。