mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Add api addtion for SIWA and add Function for Unit test
* Adding Unit test for apple signIn flow in FIROAuthProviderTests and FIRAuthTest
* remove AuthSample.xcodeproj fiels and application.plist file under Sample
* Revert "remove AuthSample.xcodeproj fiels and application.plist file under Sample"
This reverts commit 8578f964b9.
* remove changes in AuthSample 1/5
* remove changes in AuthSample 2/5
* remove changes in AuthSample 3/5
* remove changes in AuthSample 4/5
* remove changes in AuthSample 5/5
* overwrite with master firles to remove white space changes in the two files
* Delete Application.plist file
* Clean extra methods in FIROAuthCredentialInternal and related files to add displayname
* Add displayName in FIRVerifyAssertionRequest
* Fix issues in comments, merge GoogleAuthprovider, fix files in tests
* fix issues
* Clang-format all files
* Adding comment for testSignInWithCredentialSuccess
* Adding comments for testSignInWithCredentialSuccess
* Updates to reflect approved API.
* Address review comments.
* Update unit tests.
* Update changelog.
* Remove JSON pretty-print and add one more unit test.
---------
Co-authored-by: Rosalyn Tan <rosalyntan@google.com>
227 lines
7.2 KiB
Objective-C
227 lines
7.2 KiB
Objective-C
/*
|
|
* Copyright 2017 Google
|
|
*
|
|
* 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/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
/** @var kVerifyAssertionEndpoint
|
|
@brief The "verifyAssertion" endpoint.
|
|
*/
|
|
static NSString *const kVerifyAssertionEndpoint = @"verifyAssertion";
|
|
|
|
/** @var kProviderIDKey
|
|
@brief The key for the "providerId" value in the request.
|
|
*/
|
|
static NSString *const kProviderIDKey = @"providerId";
|
|
|
|
/** @var kProviderIDTokenKey
|
|
@brief The key for the "id_token" value in the request.
|
|
*/
|
|
static NSString *const kProviderIDTokenKey = @"id_token";
|
|
|
|
/** @var kProviderNonceKey
|
|
@brief The key for the "nonce" value in the request.
|
|
*/
|
|
static NSString *const kProviderNonceKey = @"nonce";
|
|
|
|
/** @var kProviderAccessTokenKey
|
|
@brief The key for the "access_token" value in the request.
|
|
*/
|
|
static NSString *const kProviderAccessTokenKey = @"access_token";
|
|
|
|
/** @var kProviderOAuthTokenSecretKey
|
|
@brief The key for the "oauth_token_secret" value in the request.
|
|
*/
|
|
static NSString *const kProviderOAuthTokenSecretKey = @"oauth_token_secret";
|
|
|
|
/** @var kIdentifierKey
|
|
@brief The key for the "identifier" value in the request.
|
|
*/
|
|
static NSString *const kIdentifierKey = @"identifier";
|
|
|
|
/** @var kRequestURIKey
|
|
@brief The key for the "requestUri" value in the request.
|
|
*/
|
|
static NSString *const kRequestURIKey = @"requestUri";
|
|
|
|
/** @var kPostBodyKey
|
|
@brief The key for the "postBody" value in the request.
|
|
*/
|
|
static NSString *const kPostBodyKey = @"postBody";
|
|
|
|
/** @var kPendingTokenKey
|
|
@brief The key for the "pendingToken" value in the request.
|
|
*/
|
|
static NSString *const kPendingTokenKey = @"pendingToken";
|
|
|
|
/** @var kAutoCreateKey
|
|
@brief The key for the "autoCreate" value in the request.
|
|
*/
|
|
static NSString *const kAutoCreateKey = @"autoCreate";
|
|
|
|
/** @var kIDTokenKey
|
|
@brief The key for the "idToken" value in the request. This is actually the STS Access Token,
|
|
despite it's confusing (backwards compatiable) parameter name.
|
|
*/
|
|
static NSString *const kIDTokenKey = @"idToken";
|
|
|
|
/** @var kReturnSecureTokenKey
|
|
@brief The key for the "returnSecureToken" value in the request.
|
|
*/
|
|
static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
|
|
|
|
/** @var kUserKey
|
|
@brief The key for the "user" value in the request. The value is a JSON object that contains the
|
|
name of the user.
|
|
*/
|
|
static NSString *const kUserKey = @"user";
|
|
|
|
/** @var kNameKey
|
|
@brief The key for the "name" value in the request. The value is a JSON object that contains the
|
|
first and/or last name of the user.
|
|
*/
|
|
static NSString *const kNameKey = @"name";
|
|
|
|
/** @var kFirstNameKey
|
|
@brief The key for the "firstName" value in the request.
|
|
*/
|
|
static NSString *const kFirstNameKey = @"firstName";
|
|
|
|
/** @var kLastNameKey
|
|
@brief The key for the "lastName" value in the request.
|
|
*/
|
|
static NSString *const kLastNameKey = @"lastName";
|
|
|
|
/** @var kReturnIDPCredentialKey
|
|
@brief The key for the "returnIdpCredential" value in the request.
|
|
*/
|
|
static NSString *const kReturnIDPCredentialKey = @"returnIdpCredential";
|
|
|
|
/** @var kSessionIDKey
|
|
@brief The key for the "sessionID" value in the request.
|
|
*/
|
|
static NSString *const kSessionIDKey = @"sessionId";
|
|
|
|
/** @var kTenantIDKey
|
|
@brief The key for the tenant id value in the request.
|
|
*/
|
|
static NSString *const kTenantIDKey = @"tenantId";
|
|
|
|
@implementation FIRVerifyAssertionRequest
|
|
|
|
- (nullable instancetype)initWithProviderID:(NSString *)providerID
|
|
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
|
|
self = [super initWithEndpoint:kVerifyAssertionEndpoint
|
|
requestConfiguration:requestConfiguration];
|
|
if (self) {
|
|
_providerID = providerID;
|
|
_returnSecureToken = YES;
|
|
_autoCreate = YES;
|
|
_returnIDPCredential = YES;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
|
|
NSURLComponents *components = [[NSURLComponents alloc] init];
|
|
NSMutableArray<NSURLQueryItem *> *queryItems =
|
|
[@[ [NSURLQueryItem queryItemWithName:kProviderIDKey value:_providerID] ] mutableCopy];
|
|
|
|
if (_providerIDToken) {
|
|
[queryItems addObject:[NSURLQueryItem queryItemWithName:kProviderIDTokenKey
|
|
value:_providerIDToken]];
|
|
}
|
|
|
|
if (_providerRawNonce) {
|
|
[queryItems addObject:[NSURLQueryItem queryItemWithName:kProviderNonceKey
|
|
value:_providerRawNonce]];
|
|
}
|
|
|
|
if (_providerAccessToken) {
|
|
[queryItems addObject:[NSURLQueryItem queryItemWithName:kProviderAccessTokenKey
|
|
value:_providerAccessToken]];
|
|
}
|
|
|
|
if (!_providerIDToken && !_providerAccessToken && !_pendingToken && !_requestURI) {
|
|
[NSException
|
|
raise:NSInvalidArgumentException
|
|
format:@"One of IDToken, accessToken, pendingToken, or requestURI must be supplied."];
|
|
}
|
|
|
|
if (_providerOAuthTokenSecret) {
|
|
[queryItems addObject:[NSURLQueryItem queryItemWithName:kProviderOAuthTokenSecretKey
|
|
value:_providerOAuthTokenSecret]];
|
|
}
|
|
|
|
if (_inputEmail) {
|
|
[queryItems addObject:[NSURLQueryItem queryItemWithName:kIdentifierKey value:_inputEmail]];
|
|
}
|
|
|
|
if (_fullName.givenName || _fullName.familyName) {
|
|
NSMutableDictionary *nameDict = [[NSMutableDictionary alloc] init];
|
|
if (_fullName.givenName) {
|
|
nameDict[kFirstNameKey] = _fullName.givenName;
|
|
}
|
|
if (_fullName.familyName) {
|
|
nameDict[kLastNameKey] = _fullName.familyName;
|
|
}
|
|
NSDictionary *userDict = [NSDictionary dictionaryWithObject:nameDict forKey:kNameKey];
|
|
NSData *userJson = [NSJSONSerialization dataWithJSONObject:userDict options:0 error:error];
|
|
[queryItems
|
|
addObject:[NSURLQueryItem
|
|
queryItemWithName:kUserKey
|
|
value:[[NSString alloc] initWithData:userJson
|
|
encoding:NSUTF8StringEncoding]]];
|
|
}
|
|
|
|
[components setQueryItems:queryItems];
|
|
NSMutableDictionary *body = [@{
|
|
kRequestURIKey : _requestURI ?: @"http://localhost", // Unused by server, but required
|
|
kPostBodyKey : [components query]
|
|
} mutableCopy];
|
|
|
|
if (_pendingToken) {
|
|
body[kPendingTokenKey] = _pendingToken;
|
|
}
|
|
if (_accessToken) {
|
|
body[kIDTokenKey] = _accessToken;
|
|
}
|
|
if (_returnSecureToken) {
|
|
body[kReturnSecureTokenKey] = @YES;
|
|
}
|
|
|
|
if (_returnIDPCredential) {
|
|
body[kReturnIDPCredentialKey] = @YES;
|
|
}
|
|
|
|
if (_sessionID) {
|
|
body[kSessionIDKey] = _sessionID;
|
|
}
|
|
|
|
if (self.tenantID) {
|
|
body[kTenantIDKey] = self.tenantID;
|
|
}
|
|
|
|
body[kAutoCreateKey] = @(_autoCreate);
|
|
|
|
return body;
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|