OAuthエコーでは、APIとやり取りしている間のOAuth 認証をサードパーティへしっかりと任せます。
例えば、ユーザーの資格情報の検証をあなたのアプリからではなくあなたのサーバ(サードパーティ)から行いたいような場合です。
OAuth エコーについての詳細な技術情報は ここで参照できます。
Use OAuth EchoOAuth Echo is a means to securely delegate OAuth authorization with a third party while interacting with an API. For example, you may wish to verify a user’s credentials from your app’s server (the third party) rather than your app. More technical information about OAuth Echo can be found here. |
TWTROAuthSigningのインスタンスを作成するには、Digits機能とTwitterいずれかからのユーザーセッションと、アプリケーション認証の設定が必要です。
The TWTRAuthConfigオブジェクトはあなたのTwitter アプリやDigits アプリを識別するための資格情報を内包します。
このオブジェクトはTwitter クラスから取得できます (後述のサンプルコードを参照してください)。
An TWTRAuthConfig object represents the user credentials of a Twitter of Digits user session.
TWTRSessionクラスとDGTSessionクラスは両方ともこのプロトコルに準拠しています。
// Objective-C
// Instantiates TWTROAuthSigning
TWTROAuthSigning *oauthSigning =
[[TWTROAuthSigning alloc]
initWithAuthConfig:
[Twitter sharedInstance].authConfig
authSession:[Twitter sharedInstance].session];
// Swift
// Instantiates TWTROAuthSigning
let oauthSigning = TWTROAuthSigning(
authConfig: Twitter.sharedInstance().authConfig,
authSession: Twitter.sharedInstance().session())
Instantiating TWTROAuthSigning
The An
// Objective-C
// Instantiates TWTROAuthSigning
TWTROAuthSigning *oauthSigning =
[[TWTROAuthSigning alloc]
initWithAuthConfig:
[Twitter sharedInstance].authConfig
authSession:[Twitter sharedInstance].session];
// Swift
// Instantiates TWTROAuthSigning
let oauthSigning = TWTROAuthSigning(
authConfig: Twitter.sharedInstance().authConfig,
authSession: Twitter.sharedInstance().session())
|
OAuth エコーを使用する最も簡単場方法は、認証ヘッダをリクエストして、アプリ外からverify_credentialsへのリクエストを作成することです。
// Objective-C
NSDictionary *authHeaders =
[oauthSigning OAuthEchoHeadersToVerifyCredentials];
// Swift
let authHeaders = oauthSigning
.OAuthEchoHeadersToVerifyCredentials()
authHeadersのディクショナリはX-Auth-Service-Provider (TWTROAuthEchoRequestURLStringKey でconstant定義されている)キー とX-Verify-Credentials-Authorization(TWTROAuthEchoAuthorizationHeaderKey でconstant定義されている)キーを保持しています。 Your backend should take the OAuth signature in X-Verify-Credentials-Authorization, and use it to set the Authorization header for a request to the URL in X-Auth-Service-Provider.
// Objective-C
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:
[NSURL URLWithString:
@"http://api.yourbackend.com/check_credentials"]];
request.allHTTPHeaderFields = authHeaders;
// Swift
let request = NSMutableURLRequest(
URL: NSURL(string:
"http://api.yourbackend.com/check_credentials"))
request.allHTTPHeaderFields = authHeaders
Creating OAuth Echo signing headersThe easiest way to use OAuth Echo is by requesting the authorization headers to make a request to verify_credentials from outside the app.
// Objective-C
NSDictionary *authHeaders =
[oauthSigning OAuthEchoHeadersToVerifyCredentials];
// Swift
let authHeaders = oauthSigning
.OAuthEchoHeadersToVerifyCredentials()
The
// Objective-C
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:
[NSURL URLWithString:
@"http://api.yourbackend.com/check_credentials"]];
request.allHTTPHeaderFields = authHeaders;
// Swift
let request = NSMutableURLRequest(
URL: NSURL(string:
"http://api.yourbackend.com/check_credentials"))
request.allHTTPHeaderFields = authHeaders
|