Skip to content

Commit 8716b3c

Browse files
committed
Merge branch 'release/1.2.2'
2 parents 9f2b1a6 + 7167803 commit 8716b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3894
-1138
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Xcode
2+
.DS_Store
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
*.xcworkspace
13+
!default.xcworkspace
14+
xcuserdata
15+
profile
16+
*.moved-aside
17+
DerivedData
18+
.idea/

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "Outsourced/JSON-Framework"]
2-
path = Outsourced/JSON-Framework
3-
url = git://github.com/nxtbgthng/json-framework.git

NXOAuth2Account+Private.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// NXOAuth2Account+Private.h
3+
// OAuth2Client
4+
//
5+
// Created by Tobias Kräntzer on 19.07.11.
6+
//
7+
// Copyright 2011 nxtbgthng. All rights reserved.
8+
//
9+
// Licenced under the new BSD-licence.
10+
// See README.md in this repository for
11+
// the full licence.
12+
//
13+
14+
#import "NXOAuth2Account.h"
15+
16+
@interface NXOAuth2Account (Private)
17+
- (id)initAccountWithOAuthClient:(NXOAuth2Client *)oauthClient accountType:(NSString *)accountType;
18+
@end

NXOAuth2Client.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
## Using the OAuth2Client
2+
3+
### Create an instance of NXOAuth2Client
4+
5+
To create an NXOAuth2Client instance you need OAuth2 credentials (client id & secret) and endpoints (authorize &
6+
token URL) for your application. You usually get them from the service you want to connect to. You also need to
7+
pass in an *delegate* which is discussed later.
8+
9+
<pre>
10+
// client is a ivar
11+
client = [[NXOAuth2Client alloc] initWithClientID:@"xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx"
12+
clientSecret:@"xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx"
13+
authorizeURL:[NSURL URLWithString:@"https://myHost/oauth2/authenticate"]
14+
tokenURL:[NSURL URLWithString:@"https://myHost/oauth2/token"]
15+
delegate:self];
16+
</pre>
17+
18+
Once you got your instance of the client you can check if you already have a valid token.
19+
20+
<pre>
21+
[client requestAccess];
22+
</pre>
23+
24+
This method triggers the authentication flow and will invoke one or more of the callback methods implemented in the clients delegate.
25+
26+
27+
### The Delegate
28+
<a name="TheDelegate"></a>
29+
The Authentication Delegate is the place to get callbacks on the status of authentication. It defines following methods:
30+
31+
<pre>
32+
@required
33+
- (void)oauthClientNeedsAuthentication:(NXOAuth2Client *)client;
34+
35+
@optional
36+
- (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client;
37+
- (void)oauthClientDidLoseAccessToken:(NXOAuth2Client *)client;
38+
- (void)oauthClient:(NXOAuth2Client *)client didFailToGetAccessTokenWithError:(NSError *)error;
39+
</pre>
40+
41+
#### The optional delegate methods
42+
43+
The first three delegate methods inform you when authentication is gained or lost, as well as when an error occurred during the process.
44+
`-oauthClientDidGetAccessToken:` for example is called when the authorization flow finishes with an access token or when your app was
45+
authorized in a previous session and the access token has been found in the keychain.
46+
47+
`-oauthClientDidLoseAccessToken:` is called whenever the token is lost. This might be the case when the token expires and there has been
48+
an error refreshing it, or when the user revokes access on the service your connecting to.
49+
50+
`-oauthClient:didFailToGetAccessTokenWithError:` returns the error that prevented the client from getting a valid access token. See the
51+
constants header file (`NXOAuth2Constants.h`) and the [section about errors](http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-3.2.1)
52+
in the OAuth2 spec for more information which errors to expect. Besides errors in the `NXOAuth2ErrorDomain` you should also handle NSURL errors
53+
in the `NSURLErrorDomain`.
54+
55+
#### The required delegate method
56+
57+
The fourth method needs to be implemented by your app and is responsible for choosing the OAuth2 authorization flow. The wrapper supports
58+
the user-agent & the user credentials flow of OAuth2 draft 10. The following two sections show you example implementations for both type of flows.
59+
60+
61+
##### User-agent flow
62+
63+
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
64+
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
65+
application or should be intercepted if you're using an internal web view. Pass this URL to the `-authorizationURLWithRedirectURL:` method
66+
of your NXOAuth2Client instance, and it will get the access token out of it.
67+
68+
<pre>
69+
- (void)oauthClientRequestedAuthorization:(NXOAuth2Client *)aClient;
70+
{
71+
// webserver flow
72+
73+
// this is your redirect url. register it with your app
74+
NSURL *authorizationURL = [client authorizationURLWithRedirectURL:[NSURL URLWithString:@"x-myapp://oauth2"]];
75+
#if TARGET_OS_IPHONE
76+
[[UIApplication sharedApplication] openURL:authorizationURL]; // this line quits the application or puts it to the background, be prepared
77+
#else
78+
[[NSWorkspace sharedWorkspace] openURL:authorizationURL];
79+
#endif
80+
}
81+
</pre>
82+
83+
##### User credentials flow
84+
85+
The user credentials flow allows your app do present the user a custom login form. Please consider that this flow is *generally discouraged*
86+
since the user has to enter his credentials in an untrusted environment and can't control what your app does with the entrusted credentials.
87+
88+
<pre>
89+
- (void)oauthClientRequestedAuthorization:(NXOAuth2Client *)aClient;
90+
{
91+
// user credentials flow
92+
[client authorizeWithUsername:username password:password];
93+
// you probably don't yet have username & password.
94+
// if so, open a view to query them from the user & call this method with the results asynchronously.
95+
}
96+
</pre>
97+
98+
### Sending requests
99+
100+
Create your request as usual but don't use NSURLConnection but `NXOAuth2Connection`. It has a similar delegate protocol but signs the request
101+
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
102+
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
103+
the delegate is deallocated.
104+
105+
<pre>
106+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://myHost/someResource"]];
107+
// retain the connection for as long as it's running.
108+
NXOAuth2Connection *connection = [[NXOAuth2Connection alloc] initWithRequest:request oauthClient:aClient delegate:self];
109+
</pre>

NXOAuth2Client.podspec

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'NXOAuth2Client'
3+
s.version = '1.2.2'
4+
s.license = {
5+
:type => 'BSD',
6+
:text => <<-LICENSETEXT
7+
Copyright © 2012, nxtbgthng GmbH
8+
9+
All rights reserved.
10+
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions are met:
13+
14+
* Redistributions of source code must retain the above copyright
15+
notice, this list of conditions and the following disclaimer.
16+
* Redistributions in binary form must reproduce the above copyright
17+
notice, this list of conditions and the following disclaimer in the
18+
documentation and/or other materials provided with the distribution.
19+
* Neither the name of nxtbgthng nor the
20+
names of its contributors may be used to endorse or promote products
21+
derived from this software without specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
LICENSETEXT
34+
}
35+
s.summary = 'Client library for OAuth2 (currently built against draft 10 of the OAuth2 spec).'
36+
s.homepage = 'https://github.com/nxtbgthng/OAuth2Client'
37+
s.author = { 'nxtbgthng' => '[email protected]'}
38+
s.source = { :git => 'https://github.com/nxtbgthng/OAuth2Client.git', :tag => "v#{s.version}" }
39+
s.source_files = 'NXOAuth2Account+Private.h', 'Sources/', 'Sources/OAuth2Client/'
40+
s.frameworks = 'Security'
41+
s.requires_arc = true
42+
end

OAuth2Client.framework-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<key>CFBundleExecutable</key>
88
<string>${EXECUTABLE_NAME}</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
10+
<string>com.nxtbgthng.${PRODUCT_NAME:rfc1034identifier}</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundlePackageType</key>
1414
<string>FMWK</string>
1515
<key>CFBundleShortVersionString</key>
16-
<string>1.0</string>
16+
<string>1.2.0</string>
1717
<key>CFBundleSignature</key>
1818
<string>????</string>
1919
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)