-
Notifications
You must be signed in to change notification settings - Fork 247
Add GIDToken Class #181
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
Add GIDToken Class #181
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
613ca94
Replace GIDSignInCallback
Alex-4-Git 372a61e
Change GIDSignInCallback in sample apps.
Alex-4-Git 26241b7
Minor improvements
Alex-4-Git c2a8240
Change the restorePreviousSignIn callback
Alex-4-Git 596e5b1
Style improvement.
Alex-4-Git b20eabb
Add GIDToken class
Alex-4-Git 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
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,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 |
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,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 |
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
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,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 |
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
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,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 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.