2013-01-24 74 views
0

我開發了一個使用Oauth 2進行授權的Rails應用程序。 當前爲了訪問API調用我傳遞access_token作爲URL參數,我聽說該標記也可以作爲標題傳遞。 傳遞access_token的最佳做法是什麼?爲什麼?傳遞access_token進行API調用的最佳做法是什麼

我使用Devise + Doorkeeper進行Oauth支持。

請給我一些寶貴意見..

回答

0

它經常可以看到目前的access_token頁眉。 外觀:什麼是標題?他們是關於請求的元信息。毫無疑問,取而代之的是元信息。

我不確定我的答案是否完整,可能會有一些額外的陷阱我不知道。如我錯了請糾正我。

1

正如標題你可以像這樣的控制器:

before_filter :authenticate 

protected 

def current_user 
    @current_user 
end 

def authenticate 
    token = request.env["HTTP_ACCESS_TOKEN"] 
    @current_user = User.where(authentication_token: token).first if token.present? 
    unless token && current_user.present? 
    #error handling goes here. 
    end 
end 
相關問題