aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2017-08-24 13:58:50 -0700
committerGravatar GitHub <noreply@github.com>2017-08-24 13:58:50 -0700
commitfb1b4ba5879e4118d73dc70f83d7678407418870 (patch)
tree1b00ea36ab7ea6fa6fc8ca95cbe7be69dbe0f992 /Firebase
parent1a857fe48fe32c9768143a81b009fe62a34fd0ec (diff)
Add get Auth domain RPC (#214)
* Add get Auth domain RPC * Fixes indentation * Addresses comments * ran tests on Example/Firebase.xcodeproj
Diffstat (limited to 'Firebase')
-rw-r--r--Firebase/Auth/Source/RPCs/FIRAuthBackend.h30
-rw-r--r--Firebase/Auth/Source/RPCs/FIRAuthBackend.m70
-rw-r--r--Firebase/Auth/Source/RPCs/FIRAuthRPCRequest.h11
-rw-r--r--Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.h41
-rw-r--r--Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.m42
-rw-r--r--Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.h36
-rw-r--r--Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.m38
-rw-r--r--Firebase/Auth/Source/RPCs/FIRIdentityToolkitRequest.m4
-rw-r--r--Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m4
9 files changed, 250 insertions, 26 deletions
diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.h b/Firebase/Auth/Source/RPCs/FIRAuthBackend.h
index b560644..65f93ce 100644
--- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.h
+++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.h
@@ -21,6 +21,8 @@
@class FIRCreateAuthURIResponse;
@class FIRGetAccountInfoRequest;
@class FIRGetAccountInfoResponse;
+@class FIRGetProjectConfigRequest;
+@class FIRGetProjectConfigResponse;
@class FIRGetOOBConfirmationCodeRequest;
@class FIRGetOOBConfirmationCodeResponse;
@class FIRResetPasswordRequest;
@@ -79,6 +81,16 @@ typedef void (^FIRCreateAuthURIResponseCallback)
typedef void (^FIRGetAccountInfoResponseCallback)
(FIRGetAccountInfoResponse *_Nullable response, NSError *_Nullable error);
+/** @typedef FIRGetProjectConfigResponseCallback
+ @brief The type of block used to return the result of a call to the getProjectInfo
+ endpoint.
+ @param response The received response, if any.
+ @param error The error which occurred, if any.
+ @remarks One of response or error will be non-nil.
+ */
+typedef void (^FIRGetProjectConfigResponseCallback)
+ (FIRGetProjectConfigResponse *_Nullable response, NSError *_Nullable error);
+
/** @typedef FIRSetAccountInfoResponseCallback
@brief The type of block used to return the result of a call to the setAccountInfo
endpoint.
@@ -233,6 +245,15 @@ typedef void (^FIRVerifyClientResponseCallback)
+ (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
callback:(FIRGetAccountInfoResponseCallback)callback;
+/** @fn getProjectConfig:callback:
+ @brief Calls the getProjectConfig endpoint, which returns configuration information for a given
+ project.
+ @param request An object wrapping the backend get request.
+ @param callback The callback.
+ */
++ (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
+ callback:(FIRGetProjectConfigResponseCallback)callback;
+
/** @fn setAccountInfo:callback:
@brief Calls the setAccountInfo endpoint, which is responsible for setting account info for a
user, for example, to sign up a new user with email and password.
@@ -389,6 +410,15 @@ typedef void (^FIRVerifyClientResponseCallback)
- (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
callback:(FIRGetAccountInfoResponseCallback)callback;
+/** @fn getProjectConfig:callback:
+ @brief Calls the getProjectInfo endpoint, which returns configuration information for a given
+ project.
+ @param request The request parameters.
+ @param callback The callback.
+ */
+- (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
+ callback:(FIRGetProjectConfigResponseCallback)callback;
+
/** @fn setAccountInfo:callback:
@brief Calls the setAccountInfo endpoint, which is responsible for setting account info for a
user, for example, to sign up a new user with email and password.
diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
index 0964d3f..0387a1a 100644
--- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
+++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
@@ -31,6 +31,8 @@
#import "FIRGetAccountInfoResponse.h"
#import "FIRGetOOBConfirmationCodeRequest.h"
#import "FIRGetOOBConfirmationCodeResponse.h"
+#import "FIRGetProjectConfigRequest.h"
+#import "FIRGetProjectConfigResponse.h"
#import "FIRResetPasswordRequest.h"
#import "FIRResetPasswordResponse.h"
#import "FIRSendVerificationCodeRequest.h"
@@ -398,6 +400,11 @@ static id<FIRAuthBackendImplementation> gBackendImplementation;
[[self implementation] getAccountInfo:request callback:callback];
}
++ (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
+ callback:(FIRGetProjectConfigResponseCallback)callback {
+ [[self implementation] getProjectConfig:request callback:callback];
+}
+
+ (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
callback:(FIRSetAccountInfoResponseCallback)callback {
[[self implementation] setAccountInfo:request callback:callback];
@@ -544,6 +551,18 @@ static id<FIRAuthBackendImplementation> gBackendImplementation;
}];
}
+- (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
+ callback:(FIRGetProjectConfigResponseCallback)callback {
+ FIRGetProjectConfigResponse *response = [[FIRGetProjectConfigResponse alloc] init];
+ [self postWithRequest:request response:response callback:^(NSError *error) {
+ if (error) {
+ callback(nil, error);
+ } else {
+ callback(response, nil);
+ }
+ }];
+}
+
- (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
callback:(FIRSetAccountInfoResponseCallback)callback {
FIRSetAccountInfoResponse *response = [[FIRSetAccountInfoResponse alloc] init];
@@ -713,33 +732,36 @@ static id<FIRAuthBackendImplementation> gBackendImplementation;
response:(id<FIRAuthRPCResponse>)response
callback:(void (^)(NSError *error))callback {
NSError *error;
- id postBody = [request unencodedHTTPRequestBodyWithError:&error];
- if (!postBody) {
- callback([FIRAuthErrorUtils RPCRequestEncodingErrorWithUnderlyingError:error]);
- return;
- }
- NSJSONWritingOptions JSONWritingOptions = 0;
- #if DEBUG
- JSONWritingOptions |= NSJSONWritingPrettyPrinted;
- #endif
-
NSData *bodyData;
- if ([NSJSONSerialization isValidJSONObject:postBody]) {
- bodyData = [NSJSONSerialization dataWithJSONObject:postBody
- options:JSONWritingOptions
- error:&error];
+ if ([request containsPostBody]) {
+ id postBody = [request unencodedHTTPRequestBodyWithError:&error];
+ if (!postBody) {
+ callback([FIRAuthErrorUtils RPCRequestEncodingErrorWithUnderlyingError:error]);
+ return;
+ }
+
+ NSJSONWritingOptions JSONWritingOptions = 0;
+ #if DEBUG
+ JSONWritingOptions |= NSJSONWritingPrettyPrinted;
+ #endif
+
+ if ([NSJSONSerialization isValidJSONObject:postBody]) {
+ bodyData = [NSJSONSerialization dataWithJSONObject:postBody
+ options:JSONWritingOptions
+ error:&error];
+ if (!bodyData) {
+ // This is an untested case. This happens exclusively when there is an error in the framework
+ // implementation of dataWithJSONObject:options:error:. This shouldn't normally occur as
+ // isValidJSONObject: should return NO in any case we should encounter an error.
+ error = [FIRAuthErrorUtils JSONSerializationErrorWithUnderlyingError:error];
+ }
+ } else {
+ error = [FIRAuthErrorUtils JSONSerializationErrorForUnencodableType];
+ }
if (!bodyData) {
- // This is an untested case. This happens exclusively when there is an error in the framework
- // implementation of dataWithJSONObject:options:error:. This shouldn't normally occur as
- // isValidJSONObject: should return NO in any case we should encounter an error.
- error = [FIRAuthErrorUtils JSONSerializationErrorWithUnderlyingError:error];
+ callback(error);
+ return;
}
- } else {
- error = [FIRAuthErrorUtils JSONSerializationErrorForUnencodableType];
- }
- if (!bodyData) {
- callback(error);
- return;
}
[_RPCIssuer asyncPostToURLWithRequestConfiguration:[request requestConfiguration]
diff --git a/Firebase/Auth/Source/RPCs/FIRAuthRPCRequest.h b/Firebase/Auth/Source/RPCs/FIRAuthRPCRequest.h
index cde0bd8..9ca4f44 100644
--- a/Firebase/Auth/Source/RPCs/FIRAuthRPCRequest.h
+++ b/Firebase/Auth/Source/RPCs/FIRAuthRPCRequest.h
@@ -30,6 +30,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSURL *)requestURL;
+@optional
+
+/** @fn containsPostBody
+ @brief Returns whether the request contains a post body or not. Requests without a post body
+ are get requests.
+ @remarks The default implementation returns YES.
+ */
+- (BOOL)containsPostBody;
+
/** @fn UnencodedHTTPRequestBodyWithError:
@brief Creates unencoded HTTP body representing the request.
@param error An out field for an error which occurred constructing the request.
@@ -37,8 +46,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error;
-@optional
-
/** @fn requestConfiguration
@brief Obtains the request configurations if available.
@return Returns the request configurations.
diff --git a/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.h b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.h
new file mode 100644
index 0000000..7c37e8d
--- /dev/null
+++ b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.h
@@ -0,0 +1,41 @@
+/*
+ * 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 "FIRIdentityToolkitRequest.h"
+
+#import "FIRAuthRPCRequest.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface FIRGetProjectConfigRequest : FIRIdentityToolkitRequest<FIRAuthRPCRequest>
+
+/** @fn initWithEndpoint:requestConfiguration:
+ @brief Please use initWithRequestConfiguration:
+ */
+- (nullable instancetype)initWithEndpoint:(NSString *)endpoint
+ requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
+ NS_UNAVAILABLE;
+
+/** @fn initWithTemporaryProof:phoneNumberAPIKey
+ @brief Designated initializer.
+ @param requestConfiguration An object containing configurations to be added to the request.
+ */
+- (nullable instancetype)initWithRequestConfiguration:
+ (FIRAuthRequestConfiguration *)requestConfiguration NS_DESIGNATED_INITIALIZER;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.m b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.m
new file mode 100644
index 0000000..8d92e9b
--- /dev/null
+++ b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigRequest.m
@@ -0,0 +1,42 @@
+/*
+ * 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 "FIRGetProjectConfigRequest.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** @var kGetProjectConfigEndPoint
+ @brief The "getProjectConfig" endpoint.
+ */
+static NSString *const kGetProjectConfigEndPoint = @"getProjectConfig";
+
+@implementation FIRGetProjectConfigRequest
+
+- (nullable instancetype)initWithRequestConfiguration:
+ (FIRAuthRequestConfiguration *)requestConfiguration {
+ NSString *APIKey = requestConfiguration.APIKey;
+ NSString *getProjectConfigURL =
+ [NSString stringWithFormat:@"%@?key=%@", kGetProjectConfigEndPoint, APIKey];
+ return [super initWithEndpoint:getProjectConfigURL requestConfiguration:requestConfiguration];
+}
+
+- (BOOL)containsPostBody {
+ return NO;
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.h b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.h
new file mode 100644
index 0000000..317ec81
--- /dev/null
+++ b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.h
@@ -0,0 +1,36 @@
+/*
+ * 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 <Foundation/Foundation.h>
+
+#import "FIRAuthRPCResponse.h"
+
+/** @class FIRGetProjectConfigResponse
+ @brief Represents the response from the getProjectConfig endpoint.
+ */
+@interface FIRGetProjectConfigResponse : NSObject <FIRAuthRPCResponse>
+
+/** @property projectID
+ @brief The unique ID pertaining to the current project.
+ */
+@property(nonatomic, strong, readonly, nullable) NSString *projectID;
+
+/** @property authorizedDomains
+ @brief A list of domains whitelisted for the current project.
+ */
+@property(nonatomic, strong, readonly, nullable) NSArray *authorizedDomains;
+
+@end
diff --git a/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.m b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.m
new file mode 100644
index 0000000..259a4fb
--- /dev/null
+++ b/Firebase/Auth/Source/RPCs/FIRGetProjectConfigResponse.m
@@ -0,0 +1,38 @@
+/*
+ * 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 "FIRGetProjectConfigResponse.h"
+
+@implementation FIRGetProjectConfigResponse
+
+- (BOOL)setWithDictionary:(NSDictionary *)dictionary
+ error:(NSError *_Nullable *_Nullable)error {
+ _projectID = [dictionary[@"projectId"] copy];
+ id authorizedDomains = dictionary[@"authorizedDomains"];
+ if ([authorizedDomains isKindOfClass:[NSString class]]) {
+ NSData *data = [authorizedDomains dataUsingEncoding:NSUTF8StringEncoding];
+ authorizedDomains = [NSJSONSerialization JSONObjectWithData:data
+ options:NSJSONReadingMutableLeaves
+ error:nil];
+ }
+ if ([authorizedDomains isKindOfClass:[NSArray class]]) {
+ _authorizedDomains = [[NSArray alloc] initWithArray:authorizedDomains
+ copyItems:YES];
+ }
+ return YES;
+}
+
+@end
diff --git a/Firebase/Auth/Source/RPCs/FIRIdentityToolkitRequest.m b/Firebase/Auth/Source/RPCs/FIRIdentityToolkitRequest.m
index c897066..a1ab482 100644
--- a/Firebase/Auth/Source/RPCs/FIRIdentityToolkitRequest.m
+++ b/Firebase/Auth/Source/RPCs/FIRIdentityToolkitRequest.m
@@ -43,6 +43,10 @@ static NSString *gAPIHost = @"www.googleapis.com";
return self;
}
+- (BOOL)containsPostBody {
+ return YES;
+}
+
- (NSURL *)requestURL {
NSString *URLString = [NSString stringWithFormat:kAPIURLFormat, gAPIHost, _endpoint, _APIKey];
NSURL *URL = [NSURL URLWithString:URLString];
diff --git a/Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m b/Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m
index 9c39e1e..786ea6c 100644
--- a/Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m
+++ b/Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m
@@ -126,6 +126,10 @@ static NSString *gAPIHost = @"securetoken.googleapis.com";
return URL;
}
+- (BOOL)containsPostBody {
+ return YES;
+}
+
- (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
NSMutableDictionary *postBody = [@{
kGrantTypeKey : [[self class] grantTypeStringWithGrantType:_grantType]