Skip to content

Commit 91e6483

Browse files
authored
Merge pull request #131 from yramanchuk/twitter-integration
Firebase UI Twitter Provider integration
2 parents 9c031b9 + e63b2ba commit 91e6483

23 files changed

+1046
-27
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <FirebaseAuthUI/FIRAuthUI.h>
18+
19+
NS_ASSUME_NONNULL_BEGIN
20+
21+
/** @class FIRTwitterAuthUI
22+
@brief AuthUI components for Twitter Sign In.
23+
*/
24+
@interface FIRTwitterAuthUI : NSObject <FIRAuthProviderUI>
25+
26+
@end
27+
28+
NS_ASSUME_NONNULL_END
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <FirebaseAuth/FIRTwitterAuthProvider.h>
18+
#import <FirebaseAuthUI/FIRAuthUIErrorUtils.h>
19+
#import <TwitterKit/TwitterKit.h>
20+
#import "FIRTwitterAuthUI.h"
21+
22+
/** @var kBundleFileName
23+
@brief The name of the bundle containing Twitter auth provider assets/resources.
24+
*/
25+
static NSString *const kBundleFileName = @"FirebaseTwitterAuthUIBundle.bundle";
26+
27+
/** @var kTableName
28+
@brief The name of the strings table to search for localized strings.
29+
*/
30+
static NSString *const kTableName = @"FirebaseTwitterAuthUI";
31+
32+
/** @var kSignInWithTwitter
33+
@brief The string key for localized button text.
34+
*/
35+
static NSString *const kSignInWithTwitter = @"SignInWithTwitter";
36+
37+
@implementation FIRTwitterAuthUI
38+
39+
/** @fn frameworkBundle
40+
@brief Returns the auth provider's resource bundle.
41+
@return Resource bundle for the auth provider.
42+
*/
43+
+ (NSBundle *)frameworkBundle {
44+
static NSBundle *frameworkBundle = nil;
45+
static dispatch_once_t predicate;
46+
dispatch_once(&predicate, ^{
47+
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
48+
NSString *frameworkBundlePath =
49+
[mainBundlePath stringByAppendingPathComponent:kBundleFileName];
50+
frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
51+
if (!frameworkBundle) {
52+
frameworkBundle = [NSBundle mainBundle];
53+
}
54+
});
55+
return frameworkBundle;
56+
}
57+
58+
/** @fn imageNamed:
59+
@brief Returns an image from the resource bundle given a resource name.
60+
@param name The name of the image file.
61+
@return The image object for the named file.
62+
*/
63+
+ (UIImage *)imageNamed:(NSString *)name {
64+
NSString *path = [[[self class] frameworkBundle] pathForResource:name ofType:@"png"];
65+
return [UIImage imageWithContentsOfFile:path];
66+
}
67+
68+
/** @fn localizedStringForKey:
69+
@brief Returns the localized text associated with a given string key. Will default to english
70+
text if the string is not available for the current localization.
71+
@param key A string key which identifies localized text in the .strings files.
72+
@return Localized value of the string identified by the key.
73+
*/
74+
+ (NSString *)localizedStringForKey:(NSString *)key {
75+
NSBundle *frameworkBundle = [[self class] frameworkBundle];
76+
return [frameworkBundle localizedStringForKey:key value:nil table:kTableName];
77+
}
78+
79+
#pragma mark - FIRAuthProviderUI
80+
81+
- (NSString *)providerID {
82+
return FIRTwitterAuthProviderID;
83+
}
84+
85+
- (NSString *)shortName {
86+
return @"Twitter";
87+
}
88+
89+
- (NSString *)signInLabel {
90+
return [[self class] localizedStringForKey:kSignInWithTwitter];
91+
}
92+
93+
- (UIImage *)icon {
94+
return [[self class] imageNamed:@"ic_twitter"];
95+
}
96+
97+
- (UIColor *)buttonBackgroundColor {
98+
return [UIColor colorWithRed:71.0f/255.0f green:154.0f/255.0f blue:234.0f/255.0f alpha:1.0f];
99+
}
100+
101+
- (UIColor *)buttonTextColor {
102+
return [UIColor whiteColor];
103+
}
104+
105+
- (void)signInWithAuth:(FIRAuth *)auth
106+
email:(nullable NSString *)email
107+
presentingViewController:(nullable UIViewController *)presentingViewController
108+
completion:(nullable FIRAuthProviderSignInCompletionBlock)completion {
109+
110+
[[Twitter sharedInstance]
111+
logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
112+
if (session) {
113+
FIRAuthCredential *credential =
114+
[FIRTwitterAuthProvider credentialWithToken:session.authToken
115+
secret:session.authTokenSecret];
116+
if (completion) {
117+
completion(credential, nil);
118+
}
119+
} else {
120+
NSError *newError =
121+
[FIRAuthUIErrorUtils providerErrorWithUnderlyingError:error
122+
providerID:FIRTwitterAuthProviderID];
123+
if (completion) {
124+
completion(nil, newError);
125+
}
126+
}
127+
}];
128+
}
129+
130+
- (void)signOutWithAuth:(FIRAuth *)auth {
131+
NSString *twitterUserID = [TWTRAPIClient clientWithCurrentUser].userID;
132+
if (twitterUserID) {
133+
[[Twitter sharedInstance].sessionStore logOutUserID:twitterUserID];
134+
}
135+
}
136+
137+
- (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(NSString *)sourceApplication {
138+
return [[Twitter sharedInstance] application:[UIApplication sharedApplication]
139+
openURL:URL options:nil];
140+
141+
}
142+
143+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <UIKit/UIKit.h>
18+
19+
//! Project version number for FirebaseTwitterAuthUI.
20+
FOUNDATION_EXPORT double FirebaseTwitterAuthUIVersionNumber;
21+
22+
//! Project version string for FirebaseTwitterAuthUI.
23+
FOUNDATION_EXPORT const unsigned char FirebaseTwitterAuthUIVersionString[];
24+
25+
#import <FirebaseTwitterAuthUI/FIRTwitterAuthUI.h>
26+
27+

FirebaseTwitterAuthUI/Info.plist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>$(CURRENT_PROJECT_VERSION)</string>
23+
<key>NSPrincipalClass</key>
24+
<string></string>
25+
</dict>
26+
</plist>
1.19 KB
Loading
Loading
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// The text of the button used to sign-in with Twitter.
2+
"SignInWithTwitter" = "Sign in with Twitter";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <XCTest/XCTest.h>
18+
19+
@interface FirebaseTwitterAuthUITests : XCTestCase
20+
21+
@end
22+
23+
@implementation FirebaseTwitterAuthUITests
24+
25+
@end

FirebaseTwitterAuthUITests/Info.plist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BNDL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
</dict>
24+
</plist>

FirebaseUI.podspec

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Pod::Spec.new do |s|
1818
all.dependency 'FirebaseUI/Auth'
1919
all.dependency 'FirebaseUI/Facebook'
2020
all.dependency 'FirebaseUI/Google'
21+
all.dependency 'FirebaseUI/Twitter'
2122
end
2223

2324
s.subspec 'Database' do |database|
@@ -44,4 +45,11 @@ Pod::Spec.new do |s|
4445
google.dependency 'GoogleSignIn', '~> 4.0'
4546
google.resources = 'FirebaseUIFrameworks/FirebaseGoogleAuthUI/Frameworks/FirebaseGoogleAuthUI.framework/*.{nib,lproj,png}'
4647
end
48+
49+
s.subspec 'Twitter' do |twitter|
50+
twitter.vendored_frameworks = ["FirebaseUIFrameworks/FirebaseTwitterAuthUI/Frameworks/FirebaseTwitterAuthUI.framework"]
51+
twitter.dependency 'FirebaseUI/Auth'
52+
twitter.dependency 'TwitterKit', '~> 2.4'
53+
twitter.resources = 'FirebaseUIFrameworks/FirebaseTwitterAuthUI/Frameworks/FirebaseTwitterAuthUI.framework/*.{nib,lproj,png}'
54+
end
4755
end

0 commit comments

Comments
 (0)