Skip to content
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
1 change: 0 additions & 1 deletion GoogleSignIn/Sources/GIDSignInInternalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))callback {
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
if (options) {
options->_interactive = YES;
Expand Down
58 changes: 58 additions & 0 deletions GoogleSignIn/Sources/GIDToken.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2022 Google LLC
*
* 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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h"

#import "GoogleSignIn/Sources/GIDToken_Private.h"

// Key constants used for encode and decode.
static NSString *const kTokenStringKey = @"tokenString";
static NSString *const kExpirationDateKey = @"expirationDate";

@implementation GIDToken

- (instancetype)initWithTokenString:(NSString *)tokenString
expirationDate:(NSDate *)expirationDate {
self = [super init];
if (self) {
_tokenString = tokenString;
_expirationDate = expirationDate;
}

return self;
}

#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
}

- (nullable instancetype)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (self) {
_tokenString = [decoder decodeObjectOfClass:[NSString class] forKey:kTokenStringKey];
_expirationDate = [decoder decodeObjectOfClass:[NSDate class] forKey:kExpirationDateKey];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:_tokenString forKey:kTokenStringKey];
[encoder encodeObject:_expirationDate forKey:kExpirationDateKey];
}

@end
32 changes: 32 additions & 0 deletions GoogleSignIn/Sources/GIDToken_Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 Google LLC
*
* 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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h"

NS_ASSUME_NONNULL_BEGIN

// Private |GIDToken| methods that are used in this SDK.
@interface GIDToken ()

// Private initializer for |GIDToken|.
// @param token The token String.
// @param expirationDate The expiration date of the token.
- (instancetype)initWithTokenString:(NSString *)tokenString
expirationDate:(NSDate *)expirationDate;

@end

NS_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
/// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
/// iOS 13+.
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// the main queue.
- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingViewController:(UIViewController *)presentingViewController
Expand All @@ -136,7 +136,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
/// iOS 13+.
/// @param hint An optional hint for the authorization server, for example the user's ID or email
/// address, to be prefilled if possible.
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// the main queue.
- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingViewController:(UIViewController *)presentingViewController
Expand Down Expand Up @@ -176,7 +176,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
/// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
/// iOS 13+.
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// @param callback The block that is called on completion. This block will be called asynchronously on
/// the main queue.
- (void)addScopes:(NSArray<NSString *> *)scopes
presentingViewController:(UIViewController *)presentingViewController
Expand Down
38 changes: 38 additions & 0 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2022 Google LLC
*
* 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 <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/// This class represents the basic information of a token.
@interface GIDToken : NSObject <NSSecureCoding>

/// The token string.
@property(nonatomic, copy, readonly) NSString *tokenString;

/// The estimated expiration date of the token.
@property(nonatomic, readonly, nullable) NSDate *expirationDate;

/// Unsupported.
+ (instancetype)new NS_UNAVAILABLE;

/// Unsupported.
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "GIDGoogleUser.h"
#import "GIDProfileData.h"
#import "GIDSignIn.h"
#import "GIDToken.h"
#import "GIDUserAuth.h"
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
#import "GIDSignInButton.h"
Expand Down
56 changes: 56 additions & 0 deletions GoogleSignIn/Tests/Unit/GIDTokenTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2022 Google LLC
//
// 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>
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h"

#import "GoogleSignIn/Sources/GIDToken_Private.h"

static NSString * const tokenString = @"tokenString";

@interface GIDTokenTest : XCTestCase {
NSDate *_date;
}
@end

@implementation GIDTokenTest

- (void)setUP {
[super setUp];
_date = [[NSDate alloc]initWithTimeIntervalSince1970:1000];
}

- (void)testInitializer {
GIDToken *token = [[GIDToken alloc]initWithTokenString:tokenString expirationDate:_date];
XCTAssertEqualObjects(token.tokenString, tokenString);
XCTAssertEqualObjects(token.expirationDate, _date);
}

- (void)testCoding {
if (@available(iOS 11, macOS 10.13, *)) {
GIDToken *token = [[GIDToken alloc]initWithTokenString:tokenString expirationDate:_date];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:token requiringSecureCoding:YES error:nil];
GIDToken *newToken = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDToken class]
fromData:data
error:nil];
XCTAssertEqualObjects(token.tokenString, newToken.tokenString);
XCTAssertEqualObjects(token.expirationDate, newToken.expirationDate);

XCTAssertTrue([GIDToken supportsSecureCoding]);
} else {
XCTSkip(@"Required API is not available for this test.");
}
}

@end