OAutsと道しるべ-どのようにサインポストにアクセストークン
-
21-09-2019 - |
質問
仕事をしていクライアントの方もやや漠然とした
ください。このようになっている( CommonsHttpOAuthConsumer
として
消費者と DefaultOAuthProvider
としてプロバイダ)
私はこの対応のトークンからやっています:
String requestToken = provider.retrieveRequestToken (OAuth.OUT_OF_BAND);
この形式のURL paramsさんの構文解析の実際のトークン 例えば:
https://foobar.com/oauth/login_authorize?oauth_token=XRFCGPbES3M2bYZy...
現在は、指示を取得しまうことが
Given the request token obtained in step 1, login with the user’s credentials (name and password) as POST parameters and sign the request with the request token/secret POST https://foobar.com/oauth/login_authorize
ことになるがんでは困る。明らかにしている入力
requestTokenのどこかにいいこと(post
はHttpPostを含むユーザー認証情報のページ):
consumer.setTokenWithSecret(requestToken, SECRET);
consumer.sign(post);
うまくいきませんでした。そして実際に生200状況がうかが 汎用エラーメッセージを表示します。
解決
retrieveRequestToken
が、それはあなたが彼らがサインインできるようにユーザーを送信する必要があることauthenticationUrlを返し、リクエストトークンを返しません。リクエストトークンがプロバイダオブジェクトに保存されます。
String authenticationUrl = provider.retrieveRequestToken( call_back_url )
注:OAuthの標準によれば、ユーザーは自分の資格情報を使用してプロバイダのサイトにサインインします。彼らは(消費者として)あなたのことを行った後にアクセストークンを取得することができ、その後、あなたがプロバイダのサイト上で自分のデータにアクセスすることができます。
// After user has signed in
provider.retrieveAccessToken(null)
// access token is saved in provider and provider knows which consumer uses it
// so now you can sign with your consumer and connect with the request
URL url = new URL( protected_resources_url )
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request)
request.connect()
は、ユーザーの資格情報を持っている場合は、あなたのスクリプトで認証を行うことができます。
// Using grails and functional-tests
get(authenticationUrl)
// Image the site shows a simple form with username/password and a login button
setRedirectEnabled false
form {
username = "mario"
password = "peach"
click "login"
}
そしてretrieveRequestToken
と上記のコードを実行します。
希望、これはあなたを助けます //ジョナス