Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShareKit LinkedIn integration, first version (github release) #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Example/ExampleShareImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)dealloc

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.toolbarItems = [NSArray arrayWithObjects:
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
Expand Down
6 changes: 5 additions & 1 deletion Classes/Example/ExampleShareLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#import "ExampleShareLink.h"
#import "SHK.h"
#import "UIWebView+SHKPlus.h"

@implementation ExampleShareLink

Expand All @@ -40,7 +41,7 @@ - (void)dealloc

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.toolbarItems = [NSArray arrayWithObjects:
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
Expand All @@ -56,6 +57,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)share
{
SHKItem *item = [SHKItem URL:webView.request.URL title:[webView pageTitle]];

[item setCustomValue:[webView pageDescription] forKey:@"linkDescription"];

SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[actionSheet showFromToolbar:self.navigationController.toolbar];
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/ShareKit/Core/Base Sharer Classes/SHKOAuthSharer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
NSString *consumerKey;
NSString *secretKey;
NSURL *authorizeCallbackURL;
NSString *realm;

NSURL *authorizeURL;
NSURL *accessURL;
Expand All @@ -52,6 +53,7 @@
@property (nonatomic, retain) NSString *consumerKey;
@property (nonatomic, retain) NSString *secretKey;
@property (nonatomic, retain) NSURL *authorizeCallbackURL;
@property (nonatomic, retain) NSString *realm;

@property (nonatomic, retain) NSURL *authorizeURL;
@property (nonatomic, retain) NSURL *accessURL;
Expand Down
8 changes: 5 additions & 3 deletions Classes/ShareKit/Core/Base Sharer Classes/SHKOAuthSharer.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@implementation SHKOAuthSharer

@synthesize consumerKey, secretKey, authorizeCallbackURL;
@synthesize consumerKey, secretKey, authorizeCallbackURL, realm;
@synthesize authorizeURL, requestURL, accessURL;
@synthesize consumer, requestToken, accessToken;
@synthesize signatureProvider;
Expand All @@ -44,6 +44,8 @@ - (void)dealloc
[consumerKey release];
[secretKey release];
[authorizeCallbackURL release];
self.realm = nil;

[authorizeURL release];
[requestURL release];
[accessURL release];
Expand Down Expand Up @@ -81,7 +83,7 @@ - (void)tokenRequest
OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:requestURL
consumer:consumer
token:nil // we don't have a Token yet
realm:nil // our service provider doesn't specify a realm
realm:self.realm // our service provider doesn't specify a realm
signatureProvider:signatureProvider];


Expand Down Expand Up @@ -189,7 +191,7 @@ - (void)tokenAccess:(BOOL)refresh
OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:accessURL
consumer:consumer
token:(refresh ? accessToken : requestToken)
realm:nil // our service provider doesn't specify a realm
realm:self.realm // our service provider doesn't specify a realm
signatureProvider:signatureProvider]; // use the default method, HMAC-SHA1

[oRequest setHTTPMethod:@"POST"];
Expand Down
3 changes: 3 additions & 0 deletions Classes/ShareKit/Core/Helpers/OAuth/OAMutableURLRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
OAConsumer *consumer;
OAToken *token;
NSString *realm;
NSString *callback;
NSString *signature;
id<OASignatureProviding> signatureProvider;
NSString *nonce;
Expand All @@ -48,6 +49,8 @@
@property(readonly) NSString *signature;
@property(readonly) NSString *nonce;

@property(nonatomic, retain) NSString *callback;

- (id)initWithURL:(NSURL *)aUrl
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
Expand Down
115 changes: 59 additions & 56 deletions Classes/ShareKit/Core/Helpers/OAuth/OAMutableURLRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (NSString *)_signatureBaseString;

@implementation OAMutableURLRequest
@synthesize signature, nonce;

@synthesize callback;
#pragma mark init

- (id)initWithURL:(NSURL *)aUrl
Expand All @@ -45,35 +45,8 @@ - (id)initWithURL:(NSURL *)aUrl
realm:(NSString *)aRealm
signatureProvider:(id<OASignatureProviding, NSObject>)aProvider
{
if (self = [super initWithURL:aUrl
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10.0])
{
consumer = [aConsumer retain];

// empty token for Unauthorized Request Token transaction
if (aToken == nil)
token = [[OAToken alloc] init];
else
token = [aToken retain];

if (aRealm == nil)
realm = [[NSString alloc] initWithString:@""];
else
realm = [aRealm retain];

// default to HMAC-SHA1
if (aProvider == nil)
signatureProvider = [[OAHMAC_SHA1SignatureProvider alloc] init];
else
signatureProvider = [aProvider retain];

[self _generateTimestamp];
[self _generateNonce];

didPrepare = NO;
}
return self;

return [self initWithURL:aUrl consumer:aConsumer token:aToken realm:aRealm signatureProvider:aProvider nonce:nil timestamp:nil];
}

// Setting a timestamp and nonce to known
Expand All @@ -86,9 +59,9 @@ - (id)initWithURL:(NSURL *)aUrl
nonce:(NSString *)aNonce
timestamp:(NSString *)aTimestamp
{
if (self = [super initWithURL:aUrl
if ((self = [super initWithURL:aUrl
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10.0])
timeoutInterval:10.0]))
{
consumer = [aConsumer retain];

Expand All @@ -103,14 +76,25 @@ - (id)initWithURL:(NSURL *)aUrl
else
realm = [aRealm retain];


self.callback = nil;

// default to HMAC-SHA1
if (aProvider == nil)
signatureProvider = [[OAHMAC_SHA1SignatureProvider alloc] init];
else
signatureProvider = [aProvider retain];

timestamp = [aTimestamp retain];
nonce = [aNonce retain];

if(timestamp)
timestamp = [aTimestamp retain];
else
[self _generateTimestamp];

if(nonce)
nonce = [aNonce retain];
else
[self _generateNonce];

didPrepare = NO;
}
Expand All @@ -121,6 +105,9 @@ - (void)dealloc
{
[consumer release];
[token release];

self.callback = nil;

[realm release];
[signatureProvider release];
[timestamp release];
Expand Down Expand Up @@ -148,43 +135,54 @@ - (void)prepare
if (didPrepare) {
return;
}

didPrepare = YES;
// sign

// sign
// Secrets must be urlencoded before concatenated with '&'
// TODO: if later RSA-SHA1 support is added then a little code redesign is needed

signature = [signatureProvider signClearText:[self _signatureBaseString]
withSecret:[NSString stringWithFormat:@"%@&%@",
[consumer.secret URLEncodedString],
[token.secret URLEncodedString]]];

// set OAuth headers
NSString *oauthToken;
if ([token.key isEqualToString:@""])
oauthToken = @""; // not used on Request Token transactions
else
oauthToken = [NSString stringWithFormat:@"oauth_token=\"%@\", ", [token.key URLEncodedString]];
NSString *oauthToken = nil;
if (!([token.key isEqualToString:@""]))
oauthToken = [NSString stringWithFormat:@"oauth_token=\"%@\"", [token.key URLEncodedString]];

NSMutableString *extraParameters = [NSMutableString string];

// Adding the optional parameters in sorted order isn't required by the OAuth spec, but it makes it possible to hard-code expected values in the unit tests.
// Adding the optional parameters in sorted order isn't required by the OAuth spec, but it makes it possible to hard-code expected values in the unit tests
for(NSString *parameterName in [[extraOAuthParameters allKeys] sortedArrayUsingSelector:@selector(compare:)])
{
[extraParameters appendFormat:@", %@=\"%@\"",
[parameterName URLEncodedString],
[[extraOAuthParameters objectForKey:parameterName] URLEncodedString]];
[extraParameters appendFormat:@", %@=\"%@\"", [parameterName URLEncodedString], [[extraOAuthParameters objectForKey:parameterName] URLEncodedString] ];
}

NSMutableArray *parameters = [NSMutableArray array];

[parameters addObject:[NSString stringWithFormat:@"realm=\"%@\"", [realm URLEncodedString]]];

NSString *oauthHeader = [NSString stringWithFormat:@"OAuth realm=\"%@\", oauth_consumer_key=\"%@\", %@oauth_signature_method=\"%@\", oauth_signature=\"%@\", oauth_timestamp=\"%@\", oauth_nonce=\"%@\", oauth_version=\"1.0\"%@",
[realm URLEncodedString],
[consumer.key URLEncodedString],
oauthToken,
[[signatureProvider name] URLEncodedString],
[signature URLEncodedString],
timestamp,
nonce,
extraParameters];

if ([callback length] > 0)
[parameters addObject:[NSString stringWithFormat:@"oauth_callback=\"%@\"", [callback URLEncodedString]]];

if(oauthToken)
[parameters addObject:oauthToken];

[parameters addObject:[NSString stringWithFormat:@"oauth_consumer_key=\"%@\"", [consumer.key URLEncodedString]]];

[parameters addObject:[NSString stringWithFormat:@"oauth_signature_method=\"%@\"", [[signatureProvider name] URLEncodedString]]];
[parameters addObject:[NSString stringWithFormat:@"oauth_signature=\"%@\"", [signature URLEncodedString]]];
[parameters addObject:[NSString stringWithFormat:@"oauth_timestamp=\"%@\"", timestamp]];
[parameters addObject:[NSString stringWithFormat:@"oauth_nonce=\"%@\"", nonce]];
[parameters addObject:@"oauth_version=\"1.0\""];

NSString *oauthHeader = [NSString stringWithFormat:@"OAuth %@%@", [parameters componentsJoinedByString:@", "], extraParameters];
[self setValue:oauthHeader forHTTPHeaderField:@"Authorization"];

SHKLog(@"Auth Header: %@", oauthHeader);

}

#pragma mark -
Expand All @@ -201,7 +199,6 @@ - (void)_generateNonce
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
NSMakeCollectable(theUUID);
nonce = (NSString *)string;
CFRelease(theUUID);
}

- (NSString *)_signatureBaseString
Expand All @@ -216,6 +213,12 @@ - (NSString *)_signatureBaseString
[parameterPairs addObject:[[OARequestParameter requestParameterWithName:@"oauth_nonce" value:nonce] URLEncodedNameValuePair]];
[parameterPairs addObject:[[OARequestParameter requestParameterWithName:@"oauth_version" value:@"1.0"] URLEncodedNameValuePair]];


if ([callback length] > 0)
{
[parameterPairs addObject:[[OARequestParameter requestParameterWithName:@"oauth_callback" value:callback] URLEncodedNameValuePair]];
}

if (![token.key isEqualToString:@""]) {
[parameterPairs addObject:[[OARequestParameter requestParameterWithName:@"oauth_token" value:token.key] URLEncodedNameValuePair]];
}
Expand All @@ -240,7 +243,7 @@ - (NSString *)_signatureBaseString
[[[self URL] URLStringWithoutQuery] URLEncodedString],
[normalizedRequestParameters URLEncodedString]];

SHKLog(@"OAMutableURLRequest parameters %@", normalizedRequestParameters);
SHKLog(@"OAMutableURLRequest Parameter Pairs: %@", normalizedRequestParameters);

return ret;
}
Expand Down
7 changes: 7 additions & 0 deletions Classes/ShareKit/Core/SHK.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ - (void)showViewController:(UIViewController *)vc
vc.modalTransitionStyle = [SHK modalTransitionStyle];

[topViewController presentModalViewController:vc animated:YES];

///// This is where you'd resize any view presented by the Sharer (JRS)
// The view size is determined by the modal view controller settings (and device)
//
// vc.view.superview.frame = CGRectMake(0, 0, 300, 300);//it's important to do this after presentModalViewController
// vc.view.superview.center = topViewController.view.center;

[(UINavigationController *)vc navigationBar].barStyle =
[(UINavigationController *)vc toolbar].barStyle = [SHK barStyle];
self.currentView = vc;
Expand Down
3 changes: 2 additions & 1 deletion Classes/ShareKit/Core/SHKSharers.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</array>
<key>services</key>
<array>
<string>SHKEvernote</string>
<string>SHKTwitter</string>
<string>SHKPinboard</string>
<string>SHKDelicious</string>
Expand All @@ -21,6 +20,8 @@
<string>SHKReadItLater</string>
<string>SHKInstapaper</string>
<string>SHKTumblr</string>
<string>SHKLinkedIn</string>
<string>SHKEvernote</string>
</array>
</dict>
</plist>
Loading