RLMSyncCredentials.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import "RLMSyncUtil.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. /// A token representing an identity provider's credentials.
  22. typedef NSString *RLMSyncCredentialsToken;
  23. /// A type representing the unique identifier of a Realm Object Server identity provider.
  24. typedef NSString *RLMIdentityProvider RLM_EXTENSIBLE_STRING_ENUM;
  25. /// The debug identity provider, which accepts any token string and creates a user associated with that token if one
  26. /// does not yet exist. Not enabled for Realm Object Server configured for production.
  27. extern RLMIdentityProvider const RLMIdentityProviderDebug;
  28. /// The username/password identity provider. User accounts are handled by the Realm Object Server directly without the
  29. /// involvement of a third-party identity provider.
  30. extern RLMIdentityProvider const RLMIdentityProviderUsernamePassword;
  31. /// A Facebook account as an identity provider.
  32. extern RLMIdentityProvider const RLMIdentityProviderFacebook;
  33. /// A Google account as an identity provider.
  34. extern RLMIdentityProvider const RLMIdentityProviderGoogle;
  35. /// A CloudKit account as an identity provider.
  36. extern RLMIdentityProvider const RLMIdentityProviderCloudKit;
  37. /**
  38. Opaque credentials representing a specific Realm Object Server user.
  39. */
  40. @interface RLMSyncCredentials : NSObject
  41. /// An opaque credentials token containing information that uniquely identifies a Realm Object Server user.
  42. @property (nonatomic, readonly) RLMSyncCredentialsToken token;
  43. /// The name of the identity provider which generated the credentials token.
  44. @property (nonatomic, readonly) RLMIdentityProvider provider;
  45. /// A dictionary containing additional pertinent information. In most cases this is automatically configured.
  46. @property (nonatomic, readonly) NSDictionary<NSString *, id> *userInfo;
  47. /**
  48. Construct and return credentials from a Facebook account token.
  49. */
  50. + (instancetype)credentialsWithFacebookToken:(RLMSyncCredentialsToken)token;
  51. /**
  52. Construct and return credentials from a Google account token.
  53. */
  54. + (instancetype)credentialsWithGoogleToken:(RLMSyncCredentialsToken)token;
  55. /**
  56. Construct and return credentials from an CloudKit account token.
  57. */
  58. + (instancetype)credentialsWithCloudKitToken:(RLMSyncCredentialsToken)token;
  59. /**
  60. Construct and return credentials from a Realm Object Server username and password.
  61. */
  62. + (instancetype)credentialsWithUsername:(NSString *)username
  63. password:(NSString *)password
  64. register:(BOOL)shouldRegister;
  65. /**
  66. Construct and return special credentials representing a token that can be directly used to open a Realm. The identity
  67. is used to uniquely identify the user across application launches.
  68. */
  69. + (instancetype)credentialsWithAccessToken:(RLMServerToken)accessToken identity:(NSString *)identity;
  70. /**
  71. Construct and return credentials with a custom token string, identity provider string, and optional user info. In most
  72. cases, the convenience initializers should be used instead.
  73. */
  74. - (instancetype)initWithCustomToken:(RLMSyncCredentialsToken)token
  75. provider:(RLMIdentityProvider)provider
  76. userInfo:(nullable NSDictionary *)userInfo NS_DESIGNATED_INITIALIZER;
  77. /// :nodoc:
  78. - (instancetype)init __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
  79. /// :nodoc:
  80. + (instancetype)new __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
  81. NS_ASSUME_NONNULL_END
  82. @end