2013-05-07 27 views
7

Tham số nhà nước theo các tài liệu của Google OAuth 2.0:OAuth 2 và thông số trạng thái giá trị của Google cần phải được đăng ký tại Url chuyển hướng

Indicates any state which may be useful to your application upon receipt of the response. The Google Authorization Server roundtrips this parameter, so your application receives the same value it sent. Possible uses include redirecting the user to the correct resource in your site, nonces, and cross-site-request-forgery mitigations.

Tôi muốn sử dụng các thông số trạng thái như một phương tiện để biết được tên miền phụ yêu cầu oauth ban đầu được bắt đầu từ. Tuy nhiên, thông số redirect_state dường như cần phải được đăng ký như một phần của "URI chuyển hướng được ủy quyền". Nếu không, tôi nhận được:

Error: redirect_uri_mismatch The redirect URI in the request: http://my_server.com/complete/google-oauth2/?redirect_state=2 did not match a registered redirect URI

Tôi muốn một giải pháp không yêu cầu đăng ký mọi giá trị redirect_state có thể có trong URI chuyển hướng được ủy quyền vì điều đó không phải là rất duy trì. Ý tưởng?

+0

Xem câu trả lời của tôi trên http://stackoverflow.com/questions/7722062/google-oauth2-redirect-uri-with-several-parameters/26014587#26014587 Cảm ơn! – Kiran

Trả lời

14

Tên tham số là state (và không redirect_state)!

Một yêu cầu mẫu OAuth theo các tài liệu google là ->

https://accounts.google.com/o/oauth2/auth? 
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile& 
state=%2Fprofile& 
redirect_uri=https%3A%2F%2Foauth2-login-demo.appspot.com%2Fcode& 
response_type=code& 
client_id=812741506391.apps.googleusercontent.com&approval_prompt=force 

Xin lưu ý State tham số và redirect_uri tham số. Tôi nghĩ bạn đã trộn lẫn cả hai.

EDIT - Xem này link của Google. Có giải thích tốt về các thông số trạng thái và xây dựng các yêu cầu web.

+5

Ah bạn đã đúng. Có lẽ nên đi ngủ sớm hơn! Cảm ơn – Henry

Các vấn đề liên quan