OAuth2 用戶映射和丟失我的 Cookie (OAuth2 User Mapping and Loosing my Cookies)


問題描述

OAuth2 用戶映射和丟失我的 Cookie (OAuth2 User Mapping and Loosing my Cookies)

Wrapping my old‑fashioned head around OAuth....

Aside from the request/response mechanics and the Authorize / Authenticate round trips (which I think I underdstand) I am struggling with mapping my MyUser object (whatever that may contain) to an OAuth token, if (actually when, not if) the user kills any cookies (encrypted or otherwise) I may have dropped on the browser.

I get MyUser info at the original Login (call it 'registration' for my site) but now MyUser comes back, all cookies are gone so he is just 'user'. Fair enough, user has to do an OAuth login again, but now I have no way of associating the new Token / Secret with MyUser data.

What am I missing?

‑‑‑ edit Aug 2/2012 ‑‑‑‑‑

Let me restate this (I am pretty sure I am being thick about this but guess thats what here is for):

As pointed out in Replies, each OAuth provider has their own mechanism. We can navigate those and get back an access Token for the user. 

Lets say Hero registers on my site using Facebook. FB returns his FB UserID and Name along with the Access Token. We are clever enough to request and get his FB Email, and we ask him some other registration q's before letting him in. Then we save this in our datastore (linked to our own User record):

OurUserId : 1234
oAuthProviderName : Facebook
oAUthProviderUserId: xxxxx
oAuthProviderUserEmail: hero@mlb.com
oAuthProviderUserName: iBeHero
oAuthToken: entracingly‑unique‑string‑of‑goop
oAuthSecret: moredata
.... etc.

and set a cookie to identify him as our user# 1234.

Now Hero goes away, kills his cookies for some reason, and then comes back to us.

Now he decides to Log In with Twitter. I have no cookie so I don't know who he is, and we go through the process again. 

To me he looks like a new user so once Twitter sends me a Token I start asking him Registration questions, clearly not right.

Turns out Twitter doesn't return an Email address so I can't match that, and even if they did (I think almost everyone else does) Hero likley has more than one Email.

It seems to me that the only tie I have between the two (or however many) logins is whatever cookies I set that have not been deleted.

Are we saying that the entire OAuth2.0 mechanism hangs on this? I can't belive that is right, but don't see another way, so I must be missing something , yes?

‑‑‑‑‑

參考解法

方法 1:

If you're using OAuth as a login mechanism as well, then make sure whichever provider you're talking to has some way of returning back a stable ID for a user. That ID is the key you'd use for looking up the user in your DB.

Different providers have different ways of doing this. For Google, details on how to do authentication with OAuth 2.0 are here. For Twitter, they use OAuth 1.0 and return the user ID when exchanging the code for an access token. Facebook has its own way of doing it as well. 

(by SerexxSteve Bazyl)

參考文件

  1. OAuth2 User Mapping and Loosing my Cookies (CC BY‑SA 3.0/4.0)

#oauth-2.0 #cookies






相關問題

OAuth2 用戶映射和丟失我的 Cookie (OAuth2 User Mapping and Loosing my Cookies)

如何在打開 Facebook 登錄對話框之前告訴 iPhone 應用用戶會發生什麼 (How to tell an iphone app user what will happen before opening Facebook login dialogue)

帶有 spring-security 的 OAuth2 - 通過 HTTP 方法限制 REST 訪問 (OAuth2 with spring-security - limit REST access by HTTP method)

帶有Phonegap 2.3.0的Facebook oAuth沒有在成功url返回令牌作為url參數 (Facebook oAuth with Phonegap 2.3.0 not returning token as url param at success url)

Dwolla API Key、Client_id 和 Client_Secret 有什麼區別? (What is the different between Dwolla API Key, Client_id & Client_Secret?)

Linkedin 應用程序具有 OAuth 用戶令牌和 OAuth 用戶密鑰,它們會過期嗎? (Linkedin Application has OAuth User Token and OAuth User Secret, Do they Expire?)

OAuth2:保護非用戶資源 (OAuth2: Protecting non-user resources)

IOS的foursquare oauth2 (foursquare oauth2 for IOS)

Spring Boot 2 Oauth 如何實現隱式代碼流 (Spring Boot 2 Oauth how to implement Implicit Code Flow)

FusionAuth - 基於邀請的用戶登錄與社交登錄 (FusionAuth - Invite based user on-boarding with social logins)

為什麼每次發送請求時都刷新訪問令牌是個壞主意? (Why is it a bad idea to refresh access token every time when I sent request?)

如何配置必須使用“密碼”授權類型從授權服務器請求令牌的客戶端 Java 應用程序? (How do I configure a client Java application which must request a token from an authorization server using a 'password' grant type?)







留言討論