-
Notifications
You must be signed in to change notification settings - Fork 483
Twitter integration #131
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
Merged
Merged
Twitter integration #131
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22f8bd4
implement Firebase Twitter Auth UI provider
yramanchuk df54c75
Merge branch 'master' of https://github.com/firebase/FirebaseUI-iOS i…
yramanchuk 599a7ad
fix building Twitter Auth module
yramanchuk a267127
fix misspellings in comments
yramanchuk e63b2ba
fix Twitter target configuration
yramanchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Copyright (c) 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <FirebaseAuthUI/FIRAuthUI.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** @class FIRTwitterAuthUI | ||
@brief AuthUI components for Twitter Sign In. | ||
*/ | ||
@interface FIRTwitterAuthUI : NSObject <FIRAuthProviderUI> | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// | ||
// Copyright (c) 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <FirebaseAuth/FIRTwitterAuthProvider.h> | ||
#import <FirebaseAuthUI/FIRAuthUIErrorUtils.h> | ||
#import <TwitterKit/TwitterKit.h> | ||
#import "FIRTwitterAuthUI.h" | ||
|
||
/** @var kBundleFileName | ||
@brief The name of the bundle containing Twitter auth provider assets/resources. | ||
*/ | ||
static NSString *const kBundleFileName = @"FirebaseTwitterAuthUIBundle.bundle"; | ||
|
||
/** @var kTableName | ||
@brief The name of the strings table to search for localized strings. | ||
*/ | ||
static NSString *const kTableName = @"FirebaseTwitterAuthUI"; | ||
|
||
/** @var kSignInWithTwitter | ||
@brief The string key for localized button text. | ||
*/ | ||
static NSString *const kSignInWithTwitter = @"SignInWithTwitter"; | ||
|
||
@implementation FIRTwitterAuthUI | ||
|
||
/** @fn frameworkBundle | ||
@brief Returns the auth provider's resource bundle. | ||
@return Resource bundle for the auth provider. | ||
*/ | ||
+ (NSBundle *)frameworkBundle { | ||
static NSBundle *frameworkBundle = nil; | ||
static dispatch_once_t predicate; | ||
dispatch_once(&predicate, ^{ | ||
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath]; | ||
NSString *frameworkBundlePath = | ||
[mainBundlePath stringByAppendingPathComponent:kBundleFileName]; | ||
frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath]; | ||
if (!frameworkBundle) { | ||
frameworkBundle = [NSBundle mainBundle]; | ||
} | ||
}); | ||
return frameworkBundle; | ||
} | ||
|
||
/** @fn imageNamed: | ||
@brief Returns an image from the resource bundle given a resource name. | ||
@param name The name of the image file. | ||
@return The image object for the named file. | ||
*/ | ||
+ (UIImage *)imageNamed:(NSString *)name { | ||
NSString *path = [[[self class] frameworkBundle] pathForResource:name ofType:@"png"]; | ||
return [UIImage imageWithContentsOfFile:path]; | ||
} | ||
|
||
/** @fn localizedStringForKey: | ||
@brief Returns the localized text associated with a given string key. Will default to english | ||
text if the string is not available for the current localization. | ||
@param key A string key which identifies localized text in the .strings files. | ||
@return Localized value of the string identified by the key. | ||
*/ | ||
+ (NSString *)localizedStringForKey:(NSString *)key { | ||
NSBundle *frameworkBundle = [[self class] frameworkBundle]; | ||
return [frameworkBundle localizedStringForKey:key value:nil table:kTableName]; | ||
} | ||
|
||
#pragma mark - FIRAuthProviderUI | ||
|
||
- (NSString *)providerID { | ||
return FIRTwitterAuthProviderID; | ||
} | ||
|
||
- (NSString *)shortName { | ||
return @"Twitter"; | ||
} | ||
|
||
- (NSString *)signInLabel { | ||
return [[self class] localizedStringForKey:kSignInWithTwitter]; | ||
} | ||
|
||
- (UIImage *)icon { | ||
return [[self class] imageNamed:@"ic_twitter"]; | ||
} | ||
|
||
- (UIColor *)buttonBackgroundColor { | ||
return [UIColor colorWithRed:71.0f/255.0f green:154.0f/255.0f blue:234.0f/255.0f alpha:1.0f]; | ||
} | ||
|
||
- (UIColor *)buttonTextColor { | ||
return [UIColor whiteColor]; | ||
} | ||
|
||
- (void)signInWithAuth:(FIRAuth *)auth | ||
email:(nullable NSString *)email | ||
presentingViewController:(nullable UIViewController *)presentingViewController | ||
completion:(nullable FIRAuthProviderSignInCompletionBlock)completion { | ||
|
||
[[Twitter sharedInstance] | ||
logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) { | ||
if (session) { | ||
FIRAuthCredential *credential = | ||
[FIRTwitterAuthProvider credentialWithToken:session.authToken | ||
secret:session.authTokenSecret]; | ||
if (completion) { | ||
completion(credential, nil); | ||
} | ||
} else { | ||
NSError *newError = | ||
[FIRAuthUIErrorUtils providerErrorWithUnderlyingError:error | ||
providerID:FIRTwitterAuthProviderID]; | ||
if (completion) { | ||
completion(nil, newError); | ||
} | ||
} | ||
}]; | ||
} | ||
|
||
- (void)signOutWithAuth:(FIRAuth *)auth { | ||
NSString *twitterUserID = [TWTRAPIClient clientWithCurrentUser].userID; | ||
if (twitterUserID) { | ||
[[Twitter sharedInstance].sessionStore logOutUserID:twitterUserID]; | ||
} | ||
} | ||
|
||
- (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(NSString *)sourceApplication { | ||
return [[Twitter sharedInstance] application:[UIApplication sharedApplication] | ||
openURL:URL options:nil]; | ||
|
||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Copyright (c) 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//! Project version number for FirebaseTwitterAuthUI. | ||
FOUNDATION_EXPORT double FirebaseTwitterAuthUIVersionNumber; | ||
|
||
//! Project version string for FirebaseTwitterAuthUI. | ||
FOUNDATION_EXPORT const unsigned char FirebaseTwitterAuthUIVersionString[]; | ||
|
||
#import <FirebaseTwitterAuthUI/FIRTwitterAuthUI.h> | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
FirebaseTwitterAuthUI/Strings/en.lproj/FirebaseTwitterAuthUI.strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// The text of the button used to sign-in with Twitter. | ||
"SignInWithTwitter" = "Sign in with Twitter"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@interface FirebaseTwitterAuthUITests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation FirebaseTwitterAuthUITests | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIRTwitterAuthUI.h
needs to be marked as a Public header (not Project header) or it'll cause build errors when integrating as a framework.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.