1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2016 Realm Inc.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ////////////////////////////////////////////////////////////////////////////
19 #import <Foundation/Foundation.h>
21 #import "RLMSyncUtil.h"
23 NS_ASSUME_NONNULL_BEGIN
25 /// A token representing an identity provider's credentials.
26 typedef NSString *RLMSyncCredentialsToken;
28 /// A type representing the unique identifier of a Realm Object Server identity provider.
29 typedef NSString *RLMIdentityProvider RLM_EXTENSIBLE_STRING_ENUM;
31 /// The debug identity provider, which accepts any token string and creates a user associated with that token if one
32 /// does not yet exist. Not enabled for Realm Object Server configured for production.
33 extern RLMIdentityProvider const RLMIdentityProviderDebug;
35 /// The username/password identity provider. User accounts are handled by the Realm Object Server directly without the
36 /// involvement of a third-party identity provider.
37 extern RLMIdentityProvider const RLMIdentityProviderUsernamePassword;
39 /// A Facebook account as an identity provider.
40 extern RLMIdentityProvider const RLMIdentityProviderFacebook;
42 /// A Google account as an identity provider.
43 extern RLMIdentityProvider const RLMIdentityProviderGoogle;
45 /// A CloudKit account as an identity provider.
46 extern RLMIdentityProvider const RLMIdentityProviderCloudKit;
48 /// A JSON Web Token as an identity provider.
49 extern RLMIdentityProvider const RLMIdentityProviderJWT;
51 /// An Anonymous account as an identity provider.
52 extern RLMIdentityProvider const RLMIdentityProviderAnonymous;
54 /// A Nickname account as an identity provider.
55 extern RLMIdentityProvider const RLMIdentityProviderNickname;
58 Opaque credentials representing a specific Realm Object Server user.
60 @interface RLMSyncCredentials : NSObject
62 /// An opaque credentials token containing information that uniquely identifies a Realm Object Server user.
63 @property (nonatomic, readonly) RLMSyncCredentialsToken token;
65 /// The name of the identity provider which generated the credentials token.
66 @property (nonatomic, readonly) RLMIdentityProvider provider;
68 /// A dictionary containing additional pertinent information. In most cases this is automatically configured.
69 @property (nonatomic, readonly) NSDictionary<NSString *, id> *userInfo;
72 Construct and return credentials from a Facebook account token.
74 + (instancetype)credentialsWithFacebookToken:(RLMSyncCredentialsToken)token;
77 Construct and return credentials from a Google account token.
79 + (instancetype)credentialsWithGoogleToken:(RLMSyncCredentialsToken)token;
82 Construct and return credentials from an CloudKit account token.
84 + (instancetype)credentialsWithCloudKitToken:(RLMSyncCredentialsToken)token;
87 Construct and return credentials from a Realm Object Server username and password.
89 + (instancetype)credentialsWithUsername:(NSString *)username
90 password:(NSString *)password
91 register:(BOOL)shouldRegister;
94 Construct and return credentials from a JSON Web Token.
96 + (instancetype)credentialsWithJWT:(NSString *)token;
99 Construct and return anonymous credentials
101 + (instancetype)anonymousCredentials;
104 Construct and return credentials from a nickname
106 + (instancetype)credentialsWithNickname:(NSString *)nickname isAdmin:(BOOL)isAdmin;
109 Construct and return special credentials representing a token that can
110 be directly used to open a Realm. The identity is used to uniquely identify
111 the user across application launches.
113 @warning The custom user identity will be deprecated in a future release.
115 @warning Do not specify a user identity that is the URL of an authentication
118 @warning When passing an access token credential into any of `RLMSyncUser`'s
119 login methods, you must always specify the same authentication server
120 URL, or none at all, every time you call the login method.
122 + (instancetype)credentialsWithAccessToken:(RLMServerToken)accessToken identity:(NSString *)identity;
125 Construct and return credentials with a custom token string, identity provider string, and optional user info. In most
126 cases, the convenience initializers should be used instead.
128 - (instancetype)initWithCustomToken:(RLMSyncCredentialsToken)token
129 provider:(RLMIdentityProvider)provider
130 userInfo:(nullable NSDictionary *)userInfo NS_DESIGNATED_INITIALIZER;
133 - (instancetype)init __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
136 + (instancetype)new __attribute__((unavailable("RLMSyncCredentials cannot be created directly")));
138 NS_ASSUME_NONNULL_END