Permalink
Browse files

Merge branch 'release/1.2.2'

  • Loading branch information...
2 parents 9f2b1a6 + 7167803 commit 8716b3c398f7a201d138a07bec16f327e72ab036 @toto toto committed Dec 23, 2012
Showing with 3,894 additions and 1,138 deletions.
  1. +18 −0 .gitignore
  2. +0 −3 .gitmodules
  3. +18 −0 NXOAuth2Account+Private.h
  4. +109 −0 NXOAuth2Client.md
  5. +42 −0 NXOAuth2Client.podspec
  6. +2 −2 OAuth2Client.framework-Info.plist
  7. +235 −235 OAuth2Client.xcodeproj/project.pbxproj
  8. +0 −1 Outsourced/JSON-Framework
  9. +178 −15 README.md
  10. +25 −0 Sources/NSData+NXOAuth2.h
  11. +48 −0 Sources/NSData+NXOAuth2.m
  12. +0 −22 Sources/NSMutableURLRequest+NXOAuth2.h
  13. +0 −47 Sources/NSMutableURLRequest+NXOAuth2.m
  14. +7 −7 Sources/NSString+NXOAuth2.h
  15. +33 −38 Sources/NSString+NXOAuth2.m
  16. +6 −6 Sources/NSURL+NXOAuth2.h
  17. +24 −24 Sources/NSURL+NXOAuth2.m
  18. +31 −0 Sources/OAuth2Client/NXOAuth2.h
  19. +19 −6 Sources/OAuth2Client/NXOAuth2AccessToken.h
  20. +242 −139 Sources/OAuth2Client/NXOAuth2AccessToken.m
  21. +46 −0 Sources/OAuth2Client/NXOAuth2Account.h
  22. +200 −0 Sources/OAuth2Client/NXOAuth2Account.m
  23. +133 −0 Sources/OAuth2Client/NXOAuth2AccountStore.h
  24. +715 −0 Sources/OAuth2Client/NXOAuth2AccountStore.m
  25. +86 −41 Sources/OAuth2Client/NXOAuth2Client.h
  26. +422 −129 Sources/OAuth2Client/NXOAuth2Client.m
  27. +33 −0 Sources/OAuth2Client/NXOAuth2ClientDelegate.h
  28. +74 −37 Sources/OAuth2Client/NXOAuth2Connection.h
  29. +484 −131 Sources/OAuth2Client/NXOAuth2Connection.m
  30. +31 −12 Sources/OAuth2Client/NXOAuth2ConnectionDelegate.h
  31. +95 −7 Sources/OAuth2Client/NXOAuth2Constants.h
  32. +26 −5 Sources/OAuth2Client/NXOAuth2Constants.m
  33. +15 −8 Sources/OAuth2Client/NXOAuth2FileStreamWrapper.h
  34. +32 −13 Sources/OAuth2Client/NXOAuth2FileStreamWrapper.m
  35. +18 −16 Sources/OAuth2Client/NXOAuth2PostBodyPart.h
  36. +38 −42 Sources/OAuth2Client/NXOAuth2PostBodyPart.m
  37. +11 −15 Sources/OAuth2Client/NXOAuth2PostBodyStream.h
  38. +109 −117 Sources/OAuth2Client/NXOAuth2PostBodyStream.m
  39. +0 −18 Sources/OAuth2Client/NXOAuth2PostBodyStreamMonitorDelegate.h
  40. +70 −0 Sources/OAuth2Client/NXOAuth2Request.h
  41. +175 −0 Sources/OAuth2Client/NXOAuth2Request.m
  42. +42 −0 Sources/OAuth2Client/NXOAuth2TrustDelegate.h
  43. +2 −2 Sources/OAuth2Client_Prefix.pch
View
@@ -0,0 +1,18 @@
+# Xcode
+.DS_Store
+build/
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+*.xcworkspace
+!default.xcworkspace
+xcuserdata
+profile
+*.moved-aside
+DerivedData
+.idea/
View
@@ -1,3 +0,0 @@
-[submodule "Outsourced/JSON-Framework"]
- path = Outsourced/JSON-Framework
- url = git://github.com/nxtbgthng/json-framework.git
@@ -0,0 +1,18 @@
+//
+// NXOAuth2Account+Private.h
+// OAuth2Client
+//
+// Created by Tobias Kräntzer on 19.07.11.
+//
+// Copyright 2011 nxtbgthng. All rights reserved.
+//
+// Licenced under the new BSD-licence.
+// See README.md in this repository for
+// the full licence.
+//
+
+#import "NXOAuth2Account.h"
+
+@interface NXOAuth2Account (Private)
+- (id)initAccountWithOAuthClient:(NXOAuth2Client *)oauthClient accountType:(NSString *)accountType;
+@end
View
@@ -0,0 +1,109 @@
+## Using the OAuth2Client
+
+### Create an instance of NXOAuth2Client
+
+To create an NXOAuth2Client instance you need OAuth2 credentials (client id & secret) and endpoints (authorize &
+token URL) for your application. You usually get them from the service you want to connect to. You also need to
+pass in an *delegate* which is discussed later.
+
+<pre>
+ // client is a ivar
+ client = [[NXOAuth2Client alloc] initWithClientID:@"xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx"
+ clientSecret:@"xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx"
+ authorizeURL:[NSURL URLWithString:@"https://myHost/oauth2/authenticate"]
+ tokenURL:[NSURL URLWithString:@"https://myHost/oauth2/token"]
+ delegate:self];
+</pre>
+
+Once you got your instance of the client you can check if you already have a valid token.
+
+<pre>
+ [client requestAccess];
+</pre>
+
+This method triggers the authentication flow and will invoke one or more of the callback methods implemented in the clients delegate.
+
+
+### The Delegate
+<a name="TheDelegate"></a>
+The Authentication Delegate is the place to get callbacks on the status of authentication. It defines following methods:
+
+<pre>
+@required
+ - (void)oauthClientNeedsAuthentication:(NXOAuth2Client *)client;
+
+@optional
+ - (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client;
+ - (void)oauthClientDidLoseAccessToken:(NXOAuth2Client *)client;
+ - (void)oauthClient:(NXOAuth2Client *)client didFailToGetAccessTokenWithError:(NSError *)error;
+</pre>
+
+#### The optional delegate methods
+
+The first three delegate methods inform you when authentication is gained or lost, as well as when an error occurred during the process.
+`-oauthClientDidGetAccessToken:` for example is called when the authorization flow finishes with an access token or when your app was
+authorized in a previous session and the access token has been found in the keychain.
+
+`-oauthClientDidLoseAccessToken:` is called whenever the token is lost. This might be the case when the token expires and there has been
+an error refreshing it, or when the user revokes access on the service your connecting to.
+
+`-oauthClient:didFailToGetAccessTokenWithError:` returns the error that prevented the client from getting a valid access token. See the
+constants header file (`NXOAuth2Constants.h`) and the [section about errors](http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-3.2.1)
+in the OAuth2 spec for more information which errors to expect. Besides errors in the `NXOAuth2ErrorDomain` you should also handle NSURL errors
+in the `NSURLErrorDomain`.
+
+#### The required delegate method
+
+The fourth method needs to be implemented by your app and is responsible for choosing the OAuth2 authorization flow. The wrapper supports
+the user-agent & the user credentials flow of OAuth2 draft 10. The following two sections show you example implementations for both type of flows.
+
+
+##### User-agent flow
+
+In the user-agent flow your app opens an internal user-agent (an embedded web view) or an external user-agent (the default browser) to open a
+site on the service your connecting to. The user enters his credentials and is redirected to an URL you define. This URL should open your
+application or should be intercepted if you're using an internal web view. Pass this URL to the `-authorizationURLWithRedirectURL:` method
+of your NXOAuth2Client instance, and it will get the access token out of it.
+
+<pre>
+- (void)oauthClientRequestedAuthorization:(NXOAuth2Client *)aClient;
+{
+ // webserver flow
+
+ // this is your redirect url. register it with your app
+ NSURL *authorizationURL = [client authorizationURLWithRedirectURL:[NSURL URLWithString:@"x-myapp://oauth2"]];
+ #if TARGET_OS_IPHONE
+ [[UIApplication sharedApplication] openURL:authorizationURL]; // this line quits the application or puts it to the background, be prepared
+ #else
+ [[NSWorkspace sharedWorkspace] openURL:authorizationURL];
+ #endif
+}
+</pre>
+
+##### User credentials flow
+
+The user credentials flow allows your app do present the user a custom login form. Please consider that this flow is *generally discouraged*
+since the user has to enter his credentials in an untrusted environment and can't control what your app does with the entrusted credentials.
+
+<pre>
+- (void)oauthClientRequestedAuthorization:(NXOAuth2Client *)aClient;
+{
+ // user credentials flow
+ [client authorizeWithUsername:username password:password];
+ // you probably don't yet have username & password.
+ // if so, open a view to query them from the user & call this method with the results asynchronously.
+}
+</pre>
+
+### Sending requests
+
+Create your request as usual but don't use NSURLConnection but `NXOAuth2Connection`. It has a similar delegate protocol but signs the request
+when an `NXOAuth2Client` is passed in. If you don't pass in the client but nil, the connection will work standalone but not sign any request. Make
+sure to retain the connection for as long as it's running. The best place for doing so is it's delegate. You can also cancel the connection if
+the delegate is deallocated.
+
+<pre>
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://myHost/someResource"]];
+ // retain the connection for as long as it's running.
+ NXOAuth2Connection *connection = [[NXOAuth2Connection alloc] initWithRequest:request oauthClient:aClient delegate:self];
+</pre>
@@ -0,0 +1,42 @@
+Pod::Spec.new do |s|
+ s.name = 'NXOAuth2Client'
+ s.version = '1.2.2'
+ s.license = {
+ :type => 'BSD',
+ :text => <<-LICENSETEXT
+ Copyright © 2012, nxtbgthng GmbH
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of nxtbgthng nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ LICENSETEXT
+ }
+ s.summary = 'Client library for OAuth2 (currently built against draft 10 of the OAuth2 spec).'
+ s.homepage = 'https://github.com/nxtbgthng/OAuth2Client'
+ s.author = { 'nxtbgthng' => 'team@nxtbgthng.com'}
+ s.source = { :git => 'https://github.com/nxtbgthng/OAuth2Client.git', :tag => "v#{s.version}" }
+ s.source_files = 'NXOAuth2Account+Private.h', 'Sources/', 'Sources/OAuth2Client/'
+ s.frameworks = 'Security'
+ s.requires_arc = true
+end
@@ -7,13 +7,13 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
- <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+ <string>com.nxtbgthng.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
- <string>1.0</string>
+ <string>1.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Oops, something went wrong.

0 comments on commit 8716b3c

Please sign in to comment.