Skip to content

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 5 commits into from
Sep 15, 2016
Merged
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
28 changes: 28 additions & 0 deletions FirebaseTwitterAuthUI/FIRTwitterAuthUI.h
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
143 changes: 143 additions & 0 deletions FirebaseTwitterAuthUI/FIRTwitterAuthUI.m
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
27 changes: 27 additions & 0 deletions FirebaseTwitterAuthUI/FirebaseTwitterAuthUI.h
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>
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2016-09-15 at 12 15 02 pm



26 changes: 26 additions & 0 deletions FirebaseTwitterAuthUI/Info.plist
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>
Binary file added FirebaseTwitterAuthUI/Resources/ic_twitter.png
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.
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";
25 changes: 25 additions & 0 deletions FirebaseTwitterAuthUITests/FirebaseTwitterAuthUITests.m
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
24 changes: 24 additions & 0 deletions FirebaseTwitterAuthUITests/Info.plist
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>
8 changes: 8 additions & 0 deletions FirebaseUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Pod::Spec.new do |s|
all.dependency 'FirebaseUI/Auth'
all.dependency 'FirebaseUI/Facebook'
all.dependency 'FirebaseUI/Google'
all.dependency 'FirebaseUI/Twitter'
end

s.subspec 'Database' do |database|
Expand All @@ -44,4 +45,11 @@ Pod::Spec.new do |s|
google.dependency 'GoogleSignIn', '~> 4.0'
google.resources = 'FirebaseUIFrameworks/FirebaseGoogleAuthUI/Frameworks/FirebaseGoogleAuthUI.framework/*.{nib,lproj,png}'
end

s.subspec 'Twitter' do |twitter|
twitter.vendored_frameworks = ["FirebaseUIFrameworks/FirebaseTwitterAuthUI/Frameworks/FirebaseTwitterAuthUI.framework"]
twitter.dependency 'FirebaseUI/Auth'
twitter.dependency 'TwitterKit', '~> 2.4'
twitter.resources = 'FirebaseUIFrameworks/FirebaseTwitterAuthUI/Frameworks/FirebaseTwitterAuthUI.framework/*.{nib,lproj,png}'
end
end
Loading