RLMSyncCredentials.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /// A JSON Web Token as an identity provider.
  38. extern RLMIdentityProvider const RLMIdentityProviderJWT;
  39. /// An Anonymous account as an identity provider.
  40. extern RLMIdentityProvider const RLMIdentityProviderAnonymous;
  41. /// A Nickname account as an identity provider.
  42. extern RLMIdentityProvider const RLMIdentityProviderNickname __deprecated_msg("Use RLMIdentityProviderUsernamePassword instead");
  43. /**
  44. Opaque credentials representing a specific Realm Object Server user.
  45. */
  46. @interface RLMSyncCredentials : NSObject
  47. /// An opaque credentials token containing information that uniquely identifies a Realm Object Server user.
  48. @property (nonatomic, readonly) RLMSyncCredentialsToken token;
  49. /// The name of the identity provider which generated the credentials token.
  50. @property (nonatomic, readonly) RLMIdentityProvider provider;
  51. /// A dictionary containing additional pertinent information. In most cases this is automatically configured.
  52. @property (nonatomic, readonly) NSDictionary<NSString *, id> *userInfo;
  53. /**
  54. Construct and return credentials from a Facebook account token.
  55. */
  56. + (instancetype)credentialsWithFacebookToken:(RLMSyncCredentialsToken)token;
  57. /**
  58. Construct and return credentials from a Google account token.
  59. */
  60. + (instancetype)credentialsWithGoogleToken:(RLMSyncCredentialsToken)token;
  61. /**
  62. Construct and return credentials from an CloudKit account token.
  63. */
  64. + (instancetype)credentialsWithCloudKitToken:(RLMSyncCredentialsToken)token;
  65. /**
  66. Construct and return credentials from a Realm Object Server username and password.
  67. */
  68. + (instancetype)credentialsWithUsername:(NSString *)username
  69. password:(NSString *)password
  70. register:(BOOL)shouldRegister;
  71. /**
  72. Construct and return credentials from a JSON Web Token.
  73. */
  74. + (instancetype)credentialsWithJWT:(NSString *)token;
  75. /**
  76. Construct and return anonymous credentials
  77. */
  78. + (instancetype)anonymousCredentials;
  79. /**
  80. Construct and return credentials from a nickname
  81. */
  82. + (instancetype)credentialsWithNickname:(NSString *)nickname isAdmin:(BOOL)isAdmin __deprecated_msg("Use +credentialsWithUsername instead");
  83. /**
  84. Construct and return special credentials representing a token that can
  85. be directly used to open a Realm. The identity is used to uniquely identify
  86. the user across application launches.
  87. @warning The custom user identity will be deprecated in a future release.
  88. @warning Do not specify a user identity that is the URL of an authentication
  89. server.
  90. @warning When passing an access token credential into any of `RLMSyncUser`'s
  91. login methods, you must always specify the same authentication server
  92. URL, or none at all, every time you call the login method.
  93. */
  94. + (instancetype)credentialsWithAccessToken:(RLMServerToken)accessToken identity:(NSString *)identity;
  95. /**
  96. Construct and return credentials with a custom token string, identity provider string, and optional user info. In most
  97. cases, the convenience initializers should be used instead.
  98. */
  99. - (instancetype)initWithCustomToken:(RLMSyncCredentialsToken)token
  100. provider:(RLMIdentityProvider)provider
  101. userInfo:(nullable NSDictionary *)userInfo NS_DESIGNATED_INITIALIZER;
  102. /// :nodoc:
  103. - (instancetype)init __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
  104. /// :nodoc:
  105. + (instancetype)new __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
  106. NS_ASSUME_NONNULL_END
  107. @end