Você pode gerenciar uma chave de API do usuário com a instância de autenticação da chave de API de um usuário, que pode ser acessada por meio da propriedadeapiKeysAuth do usuário.
Você pode criar uma chave de API do usuário com o método createAPIKey da instância de autenticação da chave de API.
Aviso
Armazenar o valor da chave de API
O SDK só retorna o valor da chave de API do usuário quando você o cria. Certifique-se de armazenar o valor key com segurança para que você possa usá-lo para se conectar.
Se você perder ou não armazenar o valor do key , não haverá como recuperá-lo. Você precisará criar uma nova chave de API do usuário.
| RLMApp *app = [RLMApp appWithId:YOUR_APP_ID]; |
|
| RLMUser *user = [app currentUser]; |
| RLMAPIKeyAuth *client = [user apiKeysAuth]; |
|
|
| [client createAPIKeyWithName:@"someKeyName" completion:^(RLMUserAPIKey *apiKey, NSError *error) { |
| if (error != nil) { |
| |
| } else { |
| |
| } |
| }]; |
| let app = App(id: YOUR_APP_SERVICES_APP_ID) |
|
|
|
|
| let user = app.currentUser! |
| let client = user.apiKeysAuth |
|
| client.createAPIKey(named: "someKeyName") { (apiKey, error) in |
| guard error == nil else { |
| print("Failed to create key: \(error!)") |
| return |
| } |
| |
| } |
Você pode procurar uma chave de API do usuário com o método fetchAPIKey da instância de autenticação da chave de API.
| RLMApp *app = [RLMApp appWithId:YOUR_APP_ID]; |
|
| RLMUser *user = [app currentUser]; |
| RLMAPIKeyAuth *client = [user apiKeysAuth]; |
|
|
| NSError *error = nil; |
| RLMObjectId *objectId = [[RLMObjectId alloc] initWithString:@"someObjectId" error:&error]; |
| [client fetchAPIKey:objectId completion:^(RLMUserAPIKey *apiKey, NSError *error) { |
| if (error != nil) { |
| |
| } else { |
| |
| } |
| }]; |
|
|
| [client fetchAPIKeysWithCompletion:^(NSArray<RLMUserAPIKey *> *keys, NSError *error) { |
| if (error != nil) { |
| |
| } else { |
| for (RLMUserAPIKey *key in keys) { |
| |
| } |
| } |
| }]; |
| let app = App(id: YOUR_APP_SERVICES_APP_ID) |
|
|
|
| let user = app.currentUser! |
| let client = user.apiKeysAuth |
|
|
| client.fetchAPIKey(ObjectId("00112233445566778899aabb")) { (maybeApiKey, error) in |
| |
| } |
|
|
| client.fetchAPIKeys { (keys, error) in |
| guard error == nil else { |
| fatalError("Failed to fetch keys: \(error!)") |
| } |
| for key in keys! { |
| |
| print(key.name) |
| } |
| } |
Você pode habilitar ou desabilitar uma chave de API do usuário com os métodos enableAPIKey e disableAPIKey da instância de autenticação da chave de API.
| RLMApp *app = [RLMApp appWithId:YOUR_APP_ID]; |
|
| RLMUser *user = [app currentUser]; |
| RLMAPIKeyAuth *client = [user apiKeysAuth]; |
|
|
| RLMObjectId *objectId = [[RLMObjectId alloc] initWithString:@"00112233445566778899aabb" error:nil]; |
| [client enableAPIKey:objectId completion:^(NSError *error) { |
| |
| }]; |
|
| RLMUserAPIKey *apiKey; |
|
|
|
|
| [client disableAPIKey:[apiKey objectId] completion:^(NSError *error) { |
| |
| }]; |
| let app = App(id: YOUR_APP_SERVICES_APP_ID) |
|
|
|
| let user = app.currentUser! |
|
| let client = user.apiKeysAuth |
|
|
| client.enableAPIKey(ObjectId("00112233445566778899aabb")) { (error) in |
| |
| } |
|
| let apiKey: UserAPIKey? |
|
|
|
|
| client.disableAPIKey(apiKey!.objectId) { (error) in |
| |
| } |
Você pode excluir uma chave de API do usuário com o método deleteAPIKey da instância de autenticação da chave de API.
| RLMApp *app = [RLMApp appWithId:YOUR_APP_ID]; |
|
| RLMUser *user = [app currentUser]; |
| RLMAPIKeyAuth *client = [user apiKeysAuth]; |
|
| RLMUserAPIKey *apiKey; |
|
|
|
| [client deleteAPIKey:[apiKey objectId] completion:^(NSError *error) { |
| |
| }]; |
| let app = App(id: YOUR_APP_SERVICES_APP_ID) |
|
|
|
| let user = app.currentUser! |
| let client = user.apiKeysAuth |
|
| let apiKey: UserAPIKey? |
|
|
|
| client.deleteAPIKey(apiKey!.objectId) { (error) in |
| guard error == nil else { |
| print("Failed to delete key: \(error!)") |
| return |
| } |
| |
| } |