3

私は現在 iOS アプリケーションを構築しており、Flattr-API v2 に Flattr-Support を含めたいと考えています。

私はすでにhttps://flattr.com/apps/でアプリケーションを作成しており、キーとシークレットを取得しています。

問題は、アプリケーション タイプとして「クライアント」を選択した場合でも、flattr のアプリケーション設定でコールバック URL を指定する必要があることです。さらに、入力フィールドでは http://... コールバック URL のみが許可されているように見えるため、コールバック URL を設定してアプリケーション (myApp://... など) を開くことはできません。

クライアント アプリケーションに Flattr oAuth プロセスを実装するにはどうすればよいですか? 非 Web ベース / iOS アプリケーションで flattr 認証を実装する方法の詳細な手順はありますか?

JDG OAuthConsumer ライブラリを使用する予定でしたが、これは機能しないようです。使用できる他の iOS ライブラリはありますか?

4

3 に答える 3

3

Flattr API v2 を使用して私の iOS アプリケーションから何かを flattr する私の実装の簡単な説明:

現在、「Mac 用 Google ツールボックス - OAuth 2 コントローラー」を使用しています: http://code.google.com/p/gtm-oauth2/

認証するトークンを作成します。

- (GTMOAuth2Authentication *)flattrAuth {

NSURL *tokenURL = [NSURL URLWithString:@"https://flattr.com/oauth/token"];
// We'll make up an arbitrary redirectURI.  The controller will watch for
// the server to redirect the web view to this URI, but this URI will not be
// loaded, so it need not be for any actual web page.
NSString *redirectURI = @"http://localhost/"; //for me localhost with / didn't work

GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"MyApplication"
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:clientKey
                                                     clientSecret:clientSecret];
return auth;
}

トークンを認証する ViewController を作成します。

- (GTMOAuth2ViewControllerTouch*)getSignInViewController{
GTMOAuth2Authentication *auth = [self flattrAuth];

// Specify the appropriate scope string, if any, according to the service's API documentation
auth.scope = @"flattr";

NSURL *authURL = [NSURL URLWithString:@"https://flattr.com/oauth/authorize"];

GTMOAuth2ViewControllerTouch *viewController;
viewController = [[[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
                                                              authorizationURL:authURL
                                                              keychainItemName:keychainItemName
                                                                      delegate:self
                                                              finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

return viewController;
}

およびデリゲート メソッド:

- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
  finishedWithAuth:(GTMOAuth2Authentication *)auth
             error:(NSError *)error {
if (error != nil) {
    DLog(@"Flattr sign-in failed with error: %@", [error localizedDescription]);
} else {
    DLog(@"Flattr Signin success");
    authToken = [auth retain];
}
}

アプリケーションで Viewcontroller を表示できます。ユーザーは flattr-login を表示して、ユーザーがアプリケーションを認証できるようにします。

この方法で認証トークンを使用してフラット化できます。

NSString* flattrURL = @"https://api.flattr.com/rest/v2/things/%qi/flattr";
NSURL* u = [NSURL URLWithString:[NSString stringWithFormat:flattrURL, item.flattrThingID]];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:u];
[authToken authorizeRequest:request completionHandler:^(NSError *error){
    if (error == nil) {
        // the request has been authorized
        NSURLConnection* connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];

        if(!connection){
            //TODO: handle error
        } else {
            [connection start];
        }
    } else {
        //TODO: handle error
    }
}];

次に、NSURLConnection デリゲート メソッドを実装し、JSON 応答を解析します。

GTMOAuth2 ライブラリを使用すると、認証済みトークンをキーチェーンに保存できます。手順については、 http://code.google.com/p/gtm-oauth2/wiki/Introduction#Retrifying_Authorization_from_the_Keychainの紹介をご覧ください。

于 2011-12-21T13:07:54.380 に答える
1

デスクトップ/モバイル アプリを認証したくない場合は、oauth2 の暗黙的な許可フローを使用したくないでしょう。flattr アプリケーションを登録するときに、アプリケーションにコールバックするアプリケーション固有の URI を使用します。iphone-application://oauth-callback.

当社でアプリケーションを認証するときは、 のresponse_type token代わりにを使用しますcode。これにより、すぐにトークンが作成され、アプリケーションにリダイレクトされます。

元。リクエスト URL:https://flattr.com/oauth/authorize?client_id=2134&redirect_uri=iphone-application://oauth-callback&response_type=token

リソース所有者がアプリケーションを承認する場合、HTTP 302 を送信し、リダイレクト URI にリダイレクトします。

元。応答 302 場所:iphone-application://oauth-callback#access_token=e5oNJ4917WAaJaO4zvoVV2dt3GYClPzp&token_type=bearer

現在、暗黙的な許可を行う方法を説明する詳細なドキュメントはありませんが、ドキュメントの作成に取り組んでいます。その間、私はすべての耳です。

https://github.com/nxtbgthng/OAuth2Clientは iOS の oauth2 ライブラリですが、それが良いかどうかはわかりません。

于 2011-12-19T07:51:04.487 に答える
0

これはよさそうだ:https ://github.com/neonichu/FlattrKit

于 2012-07-07T07:13:49.087 に答える