FIRAuthWebUtils.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRAuthRequestConfiguration;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @typedef FIRFetchAuthDomainCallback
  20. @brief The callback invoked at the end of the flow to fetch the Auth domain.
  21. @param authDomain The Auth domain.
  22. @param error The error that occurred while fetching the auth domain, if any.
  23. */
  24. typedef void (^FIRFetchAuthDomainCallback)(NSString *_Nullable authDomain,
  25. NSError *_Nullable error);
  26. /** @class FIRAuthURLUtils
  27. @brief A utility class used to facilitate the creation of auth related URLs.
  28. */
  29. @interface FIRAuthWebUtils : NSObject
  30. /** @fn randomStringWithLength:
  31. @brief Generates a random string of a specified length.
  32. */
  33. + (NSString *)randomStringWithLength:(NSUInteger)length;
  34. /** @fn isCallbackSchemeRegisteredForCustomURLScheme:
  35. @brief Checks whether or not the provided custom URL scheme has been registered by the app.
  36. @param URLScheme The custom URL scheme to be checked against all custom URL schemes registered
  37. by the app.
  38. @return whether or not the provided custom URL scheme has been registered by the app.
  39. */
  40. + (BOOL)isCallbackSchemeRegisteredForCustomURLScheme:(NSString *)URLScheme;
  41. /** @fn isExpectedCallbackURL:eventID:authType
  42. @brief Parses a URL into all available query items.
  43. @param URL The actual callback URL.
  44. @param eventID The expected event ID.
  45. @param authType The expected auth type.
  46. @param callbackScheme The expected callback custom scheme.
  47. @return Whether or not the actual callback URL matches the expected callback URL.
  48. */
  49. + (BOOL)isExpectedCallbackURL:(nullable NSURL *)URL
  50. eventID:(NSString *)eventID
  51. authType:(NSString *)authType
  52. callbackScheme:(NSString *)callbackScheme;
  53. /** @fn fetchAuthDomainWithCompletion:completion:
  54. @brief Fetches the auth domain associated with the Firebase Project.
  55. @param completion The callback invoked after the auth domain has been constructed or an error
  56. has been encountered.
  57. */
  58. + (void)fetchAuthDomainWithRequestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
  59. completion:(FIRFetchAuthDomainCallback)completion;
  60. /** @fn queryItemValue:from:
  61. @brief Utility function to get a value from a NSURLQueryItem array.
  62. @param name The key.
  63. @param queryList The NSURLQueryItem array.
  64. @return The value for the key.
  65. */
  66. + (nullable NSString *)queryItemValue:(NSString *)name from:(NSArray<NSURLQueryItem *> *)queryList;
  67. /** @fn dictionaryWithHttpArgumentsString:
  68. @brief Utility function to get a dictionary from a http argument string.
  69. @param argString The http argument string.
  70. @return The resulting dictionary of query arguments.
  71. */
  72. + (NSDictionary *)dictionaryWithHttpArgumentsString:(NSString *)argString;
  73. /** @fn stringByUnescapingFromURLArgument:from:
  74. @brief Utility function to get a string by unescapting URL arguments.
  75. @param argument The argument string.
  76. @return The resulting string after unescaping URL argument.
  77. */
  78. + (NSString *)stringByUnescapingFromURLArgument:(NSString *)argument;
  79. /** @fn parseURL:
  80. @brief Parses an incoming URL into all available query items.
  81. @param urlString The url to be parsed.
  82. @return A dictionary of available query items in the target URL.
  83. */
  84. + (NSDictionary<NSString *, NSString *> *)parseURL:(NSString *)urlString;
  85. @end
  86. NS_ASSUME_NONNULL_END