• R/O
  • R/W (SSH)
  • R/W (HTTPS)

afficheur: Commit Details


Commit MetaInfo

Revision809 (tree)
Time2011-09-25 20:20:22
Authorichi

Log Message

facebook:セキュリティ設定でセキュア接続をオンにするとOAuth認可できない不具合を修正

Change Summary

Diff

--- Afficheur/trunk/ServiceTumblr.m (revision 808)
+++ Afficheur/trunk/ServiceTumblr.m (revision 809)
@@ -6,6 +6,7 @@
66 // Copyright 2008 Katsuhiko Ichinose. All rights reserved.
77 //
88
9+#import "ServiceTumblrKey.h"
910 #import "ServiceTumblr.h"
1011 #import "AfficheurController.h"
1112 #import "AfficheurPreferences.h"
@@ -18,6 +19,66 @@
1819
1920 @implementation ServiceTumblr
2021
22+static NSString* REQUEST_TOKEN_PATH = @"http://tumblr.com/oauth/request_token";
23+static NSString* AUTHORIZE_PATH = @"http://tumblr.com/oauth/authorize";
24+static NSString* ACCESS_TOKEN_PATH = @"http://tumblr.com/oauth/access_token";
25+
26+- (NSString *)authorize
27+{
28+ LOG(@"[%@ authorize]", [self className]);
29+ NSString *authorize = nil;
30+ @try
31+ {
32+ OAuth *oAuth = [[OAuth alloc] init];
33+ [oAuth setConsumerKey:CONSUMER_KEY];
34+ [oAuth setConsumerSecret:CONSUMER_SECRET];
35+ [oAuth setRequestTokenPath:REQUEST_TOKEN_PATH];
36+ [oAuth setAuthorizePath:AUTHORIZE_PATH];
37+ [oAuth setAccessTokenPath:ACCESS_TOKEN_PATH];
38+ if ([oAuth request_token])
39+ {
40+ [self setRequestToken:[oAuth requestToken]];
41+ [self setRequestTokenSecret:[oAuth requestTokenSecret]];
42+ authorize = [NSString stringWithFormat:
43+ @"%@?oauth_token=%@&perms=delete",
44+ [oAuth authorizePath], [oAuth requestToken]];
45+ }
46+ }
47+ @catch (NSException *exception)
48+ {
49+ EXPLOG(@"[%@ authorize] EXCEPTION\n%@: %@", [self className], [exception name], [exception reason]);
50+ }
51+ return authorize;
52+}
53+
54+- (BOOL)access_token:(NSString *)pin
55+{
56+ LOG(@"[%@ access_token]", [self className]);
57+ BOOL access_token = NO;
58+ @try
59+ {
60+ OAuth *oAuth = [[OAuth alloc] init];
61+ [oAuth setConsumerKey:CONSUMER_KEY];
62+ [oAuth setConsumerSecret:CONSUMER_SECRET];
63+ [oAuth setRequestToken:_request_token];
64+ [oAuth setRequestTokenSecret:_request_token_secret];
65+ [oAuth setRequestTokenPath:REQUEST_TOKEN_PATH];
66+ [oAuth setAuthorizePath:AUTHORIZE_PATH];
67+ [oAuth setAccessTokenPath:ACCESS_TOKEN_PATH];
68+ if ([oAuth access_tokenWithPIN:pin])
69+ {
70+ [self setAccessToken:[oAuth accessToken]];
71+ [self setAccessTokenSecret:[oAuth accessTokenSecret]];
72+ access_token = YES;
73+ }
74+ }
75+ @catch (NSException *exception)
76+ {
77+ EXPLOG(@"[%@ access_token] EXCEPTION\n%@: %@", [self className], [exception name], [exception reason]);
78+ }
79+ return access_token;
80+}
81+
2182 - (BOOL)checkRetrieveTimeline:(NSDate *)now
2283 {
2384 BOOL check = NO;
--- Afficheur/trunk/i18n.h (revision 808)
+++ Afficheur/trunk/i18n.h (revision 809)
@@ -64,6 +64,7 @@
6464
6565 APPKIT_EXTERN NSString* i18nPleaseTwitterAuthorize;
6666 APPKIT_EXTERN NSString* i18nPleaseJaikuAuthorize;
67+APPKIT_EXTERN NSString* i18nPleaseTumblrAuthorize;
6768 APPKIT_EXTERN NSString* i18nPleaseFriendFeedAuthorize;
6869 APPKIT_EXTERN NSString* i18nPleaseFaceBookAuthorize;
6970
@@ -123,6 +124,7 @@
123124
124125 #define PLEASE_TWITTER_AUTHORIZE NSLocalizedString(i18nPleaseTwitterAuthorize, @"")
125126 #define PLEASE_JAIKU_AUTHORIZE NSLocalizedString(i18nPleaseJaikuAuthorize, @"")
127+#define PLEASE_TUMBLR_AUTHORIZE NSLocalizedString(i18nPleaseTumblrAuthorize, @"")
126128 #define PLEASE_FRIENDFEED_AUTHORIZE NSLocalizedString(i18nPleaseFriendFeedAuthorize, @"")
127129 #define PLEASE_FACEBOOK_AUTHORIZE NSLocalizedString(i18nPleaseFaceBookAuthorize, @"")
128130
--- Afficheur/trunk/i18n.m (revision 808)
+++ Afficheur/trunk/i18n.m (revision 809)
@@ -62,6 +62,7 @@
6262
6363 NSString* i18nPleaseTwitterAuthorize = @"Please Twitter Authorize";
6464 NSString* i18nPleaseJaikuAuthorize = @"Please Jaiku Authorize";
65+NSString* i18nPleaseTumblrAuthorize = @"Please Tumblr Authorize";
6566 NSString* i18nPleaseFriendFeedAuthorize = @"Please FriendFeed Authorize";
6667 NSString* i18nPleaseFaceBookAuthorize = @"Please FaceBook Authorize";
6768
--- Afficheur/trunk/AfficheurPreferences.h (revision 808)
+++ Afficheur/trunk/AfficheurPreferences.h (revision 809)
@@ -91,11 +91,13 @@
9191 IBOutlet id _webOK;
9292 IBOutlet id _textJaikuToken;
9393 IBOutlet id _textTwitterToken;
94+ IBOutlet id _textTumblrToken;
9495 IBOutlet id _textFriendFeedToken;
9596 IBOutlet id _textFaceBookUser;
9697 IBOutlet id _textFaceBookToken;
9798 IBOutlet id _btnJaikuAuthorize;
9899 IBOutlet id _btnTwitterAuthorize;
100+ IBOutlet id _btnTumblrAuthorize;
99101 IBOutlet id _btnFriendFeedAuthorize;
100102 IBOutlet id _btnFaceBookAuthorize;
101103 IBOutlet id _textPleaseAuthorize;
@@ -260,6 +262,8 @@
260262 - (NSString *)accountTumblrPass;
261263 - (BOOL)accountTumblrExecMenu;
262264 - (NSTimeInterval)accountTumblrIntervalTimeline;
265+- (NSString *)accountTumblrOAuthKey;
266+- (NSString *)accountTumblrOAuthSecret;
263267 - (NSString *)accountWassrUser;
264268 - (NSString *)accountWassrPass;
265269 - (BOOL)accountWassrExecMenu;
@@ -371,6 +375,7 @@
371375
372376 - (IBAction)onJaikuAuthorize:(id)sender;
373377 - (IBAction)onTwitterAuthorize:(id)sender;
378+- (IBAction)onTumblrAuthorize:(id)sender;
374379 - (IBAction)onFriendFeedAuthorize:(id)sender;
375380 - (IBAction)onFaceBookAuthorize:(id)sender;
376381
--- Afficheur/trunk/AfficheurPreferences.m (revision 808)
+++ Afficheur/trunk/AfficheurPreferences.m (revision 809)
@@ -14,6 +14,7 @@
1414 #import "Service.h"
1515 #import "ServiceJaiku.h"
1616 #import "ServiceTwitter.h"
17+#import "ServiceTumblr.h"
1718 #import "ServiceFriendFeed.h"
1819 #import "ServiceFaceBook.h"
1920 #import "KeyEquivView.h"
@@ -139,6 +140,8 @@
139140 static NSString* AccountTumblrPass = @"Account.Tumblr.Pass";
140141 static NSString* AccountTumblrExecMenu = @"Account.Tumblr.ExecMenu";
141142 static NSString* AccountTumblrIntervalTimeline = @"Account.Tumblr.IntervalTimeline";
143+static NSString* AccountTumblrOAuthKey = @"Account.Tumblr.OAuth.access_key";
144+static NSString* AccountTumblrOAuthSecret = @"Account.Tumblr.OAuth.access_secret";
142145 static NSString* AccountWassrUser = @"Account.Wassr.User";
143146 static NSString* AccountWassrPass = @"Account.Wassr.Pass";
144147 static NSString* AccountWassrExecMenu = @"Account.Wassr.ExecMenu";
@@ -1407,6 +1410,16 @@
14071410 return [self accountInterval:AccountTumblrIntervalTimeline];
14081411 }
14091412
1413+- (NSString *)accountTumblrOAuthKey
1414+{
1415+ return [[NSUserDefaults standardUserDefaults] stringForKey:AccountTumblrOAuthKey];
1416+}
1417+
1418+- (NSString *)accountTumblrOAuthSecret
1419+{
1420+ return [[NSUserDefaults standardUserDefaults] stringForKey:AccountTumblrOAuthSecret];
1421+}
1422+
14101423 - (NSString *)accountWassrUser
14111424 {
14121425 return [[NSUserDefaults standardUserDefaults] stringForKey:AccountWassrUser];
@@ -2703,6 +2716,136 @@
27032716 [NSThread exit];
27042717 }
27052718
2719+#pragma mark OAuth of Tumblr
2720+
2721+- (void)adjustTumblrAuthorizeButton
2722+{
2723+ [self adjustAuthorizeButton:_btnTumblrAuthorize
2724+ withAccessToken:[self accountTumblrOAuthKey]
2725+ secret:[self accountTumblrOAuthSecret]];
2726+}
2727+
2728+- (void)setTumblrAccessToken
2729+{
2730+ LOG(@"[%@ setTumblrAccessToken]", [self className]);
2731+ ServiceTumblr *tumblr = (ServiceTumblr *)[_controller service:Tumblr];
2732+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
2733+ [defaults setValue:[tumblr accessToken]
2734+ forKey:AccountTumblrOAuthKey];
2735+ [defaults setValue:[tumblr accessTokenSecret]
2736+ forKey:AccountTumblrOAuthSecret];
2737+ [_textTumblrToken setStringValue:[tumblr accessToken]];
2738+ [self adjustTumblrAuthorizeButton];
2739+}
2740+
2741+- (void)removeTumblrAccessToken:(NSNumber *)returnCode
2742+{
2743+ LOG(@"[%@ removeTumblrAccessToken]", [self className]);
2744+ @try
2745+ {
2746+ if ([returnCode intValue] == DIALOG_OK)
2747+ {
2748+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
2749+ [defaults removeObjectForKey:AccountTumblrOAuthKey];
2750+ [defaults removeObjectForKey:AccountTumblrOAuthSecret];
2751+ [_textTumblrToken setStringValue:@""];
2752+ [self adjustTumblrAuthorizeButton];
2753+ }
2754+ }
2755+ @catch (NSException *exception)
2756+ {
2757+ EXPLOG(@"[%@ removeTumblrAccessToken] EXCEPTION\n%@: %@", [self className], [exception name], [exception reason]);
2758+ }
2759+}
2760+
2761+- (void)performTumblrAccessToken
2762+{
2763+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2764+ //LOG(@"[%@ performTumblrAccessToken]", [self className]);
2765+ @try
2766+ {
2767+ NSData *data = [[[_webView mainFrame] dataSource] data];
2768+ NSString *html = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
2769+ // NSString *pin = [html replaceWithExpression:@"^.*<div id\\=\"oauth_pin\">\\s+(\\S+).*$"
2770+ // replace:@"\\1"
2771+ // options:OgreMultilineOption];
2772+ NSString *pin = [html replaceWithExpression:@"^.*<kbd aria\\-labelledby\\=\"code-desc\"><code>(.*?)<\\/code>.*$"
2773+ replace:@"\\1"
2774+ options:OgreMultilineOption];
2775+ LOG(@"[%@ performTumblrAccessToken]\n%@", [self className], html);
2776+ LOG(@"[%@ performTumblrAccessToken]\n'%@'", [self className], pin);
2777+ if ([pin lengthOfRegularExpression:@"^\\S+$"] == [pin length])
2778+ {
2779+ ServiceTumblr *tumblr = (ServiceTumblr *)[_controller service:Tumblr];
2780+ if ([tumblr access_token:pin])
2781+ {
2782+ LOG(@"[%@ performTumblrAccessToken]\n%@\n%@", [self className], [tumblr accessToken], [tumblr accessTokenSecret]);
2783+ [self performSelectorOnMainThread:@selector(setTumblrAccessToken)
2784+ withObject:nil
2785+ waitUntilDone:YES];
2786+ }
2787+ }
2788+ }
2789+ @catch (NSException *exception)
2790+ {
2791+ EXPLOG(@"[%@ performTumblrAccessToken] EXCEPTION\n%@: %@", [self className], [exception name], [exception reason]);
2792+ }
2793+ LOG(@"[%@ performTumblrTumblrToken] done", [self className]);
2794+ [pool release];
2795+ [NSThread exit];
2796+}
2797+
2798+- (void)performTumblrBeginWebSheet:(NSString *)path
2799+{
2800+ LOG(@"[%@ performTumblrBeginWebSheet]\n%@", [self className], path);
2801+ [self beginWebSheet:path
2802+ enabledURL:@"http://www.tumblr.com/oauth/authorize"
2803+ selector:@selector(performTumblrAccessToken)
2804+ target:self
2805+ text:PLEASE_TUMBLR_AUTHORIZE];
2806+}
2807+
2808+- (void)performTumblrBeginConfirm:(id)object
2809+{
2810+ [self beginConfirmSheetWithText:REMOVE_TOKEN
2811+ selector:@selector(removeTumblrAccessToken:)
2812+ target:self];
2813+}
2814+
2815+- (void)performTumblrAuthorize
2816+{
2817+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2818+ LOG(@"[%@ performTumblrAuthorize]", [self className]);
2819+ @try
2820+ {
2821+ if ([[_btnTumblrAuthorize title] isEqualToString:AUTHORIZE])
2822+ {
2823+ ServiceTumblr *tumblr = (ServiceTumblr *)[_controller service:Tumblr];
2824+ NSString *path = [tumblr authorize];
2825+ if (path)
2826+ {
2827+ LOG(@"[%@ performTumblrAuthorize]\n%@", [self className], path);
2828+ [self performSelectorOnMainThread:@selector(performTumblrBeginWebSheet:)
2829+ withObject:path
2830+ waitUntilDone:YES];
2831+ }
2832+ }
2833+ else
2834+ {
2835+ [self performSelectorOnMainThread:@selector(performTumblrBeginConfirm:)
2836+ withObject:nil
2837+ waitUntilDone:YES];
2838+ }
2839+ }
2840+ @catch (NSException *exception)
2841+ {
2842+ EXPLOG(@"[%@ performTumblrAuthorize] EXCEPTION\n%@: %@", [self className], [exception name], [exception reason]);
2843+ }
2844+ LOG(@"[%@ performTwitterAuthorize] done", [self className]);
2845+ [pool release];
2846+ [NSThread exit];
2847+}
2848+
27062849 #pragma mark OAuth of FriendFeed
27072850
27082851 - (void)adjustFriendFeedAuthorizeButton
@@ -2906,7 +3049,7 @@
29063049 - (void)performFaceBookBeginWebSheet:(NSString *)path
29073050 {
29083051 [self beginWebSheet:path
2909- enabledURL:@"http://www.facebook.com/connect/login_success.html"
3052+ enabledURL:@"(:?http|https)://www.facebook.com/connect/login_success.html"
29103053 selector:@selector(performFaceBookAccessToken)
29113054 target:self
29123055 text:PLEASE_FACEBOOK_AUTHORIZE];
@@ -4393,7 +4536,7 @@
43934536 url = [array objectAtIndex:0];
43944537 }
43954538 LOG2(@"[%@ didFinishLoadForFrame]\n%@", [self className], url);
4396- if ([url isEqualToString:_enabledURL])
4539+ if ([url lengthOfRegularExpression:_enabledURL] > 0)
43974540 {
43984541 [_webOK setEnabled:YES];
43994542 }
@@ -4474,6 +4617,13 @@
44744617 withObject:nil];
44754618 }
44764619
4620+- (IBAction)onTumblrAuthorize:(id)sender
4621+{
4622+// [NSThread detachNewThreadSelector:@selector(performTumblrAuthorize)
4623+// toTarget:self
4624+// withObject:nil];
4625+}
4626+
44774627 - (IBAction)onFriendFeedAuthorize:(id)sender
44784628 {
44794629 [NSThread detachNewThreadSelector:@selector(performFriendFeedAuthorize)
--- Afficheur/trunk/ServiceTwitter.h (revision 808)
+++ Afficheur/trunk/ServiceTwitter.h (revision 809)
@@ -41,6 +41,11 @@
4141 WithController:(AfficheurController *)controller
4242 preferences:(AfficheurPreferences *)preferences;
4343
44+- (void)setRequestToken:(NSString *)requestToken;
45+- (void)setRequestTokenSecret:(NSString *)requestTokenSecret;
46+- (void)setAccessToken:(NSString *)accessToken;
47+- (void)setAccessTokenSecret:(NSString *)accessTokenSecret;
48+
4449 - (NSString *)authorize;
4550 - (BOOL)access_token:(NSString *)pin;
4651 - (NSString *)accessToken;
旧リポジトリブラウザで表示