#realm #swift3
#область #swift3
Вопрос:
Я использую Google для аутентификации, например, следующим образом:
let credential = Credential.google(token: "<SOME-HASH-HERE>.apps.googleusercontent.com")
SyncUser.authenticate(with: credential, server: serverURL, timeout: 60) { [weak self] user, error in
guard nil == error else {
print("error while authenticating: (error!)")
return
}
…
}
Выдает ошибку 400. После некоторой отладки я нашел больше информации о проблеме, но все еще не уверен, что с этим не так. Итак, ответ выглядит так:
{
"invalid_params":[
{
"name":"provider",
"reason":"Unknown provider!"
}
],
"status":400,
"type":"https://realm.io/docs/object-server/problems/invalid-parameters",
"title":"Your request parameters did not validate!",
"code":601
}
Вот тело запроса:
{
"provider":"google",
"app_id":"com.blabla.bla-bla-bla",
"data":"<SOME-HASH-HERE>.apps.googleusercontent.com"
}
Я взял код аутентификации из примера из официальной документации и использую последнюю версию Realm framework.
Я также проверил аутентификацию с помощью Facebook, но она выдает ту же ошибку.
Я проверил конфигурацию.файл yml на сервере и раскомментировал google
и facebook
, разместил необходимые данные и перезапустил систему. Не помогает.
Кто-нибудь испытывает такую же проблему?
PS: configuration.yml (только часть с providers
):
# Realm Object Server Configuration
#
# For each possible setting, the commented out values are the default values
# unless another default is mentioned explicitly.
#
# Paths specified in this file can be either absolute or relative.
# Relative paths are relative to the current working directory.
providers:
## Providers of authentication tokens. Each provider has a configuration
## object associated with it. If a provider is included here and its
## configuration is valid, it will be enabled.
## Possible providers: cloudkit, debug, facebook, realm, password
## Providers 'realm' and 'password' are always enabled:
## - The 'realm' provider is used to derive access tokens from a refresh token.
## - The 'password' provider is required for the dashboard to work. It supports
## authentication through username/password and uses a PBKDF2 implementation.
## This enables authentication via a Google Sign-In access token for a
## specific app.
google:
## The client ID as retrieved when setting up the app in the Google
## Developer Console.
clientId: '<SOME-HASH-HERE>.apps.googleusercontent.com'
## This enables authentication via a Facebook access token for a specific app.
## This provider needs no configuration (uncommenting the next line enables it).
facebook: {}
После того, как я внес изменения в этот файл, я позвонил
sudo service realm-object-server restart
И на всякий случай я также перезагружаю систему.
Комментарии:
1. Пожалуйста, опубликуйте соответствующую конфигурацию сервера и информацию о том, как вы перезапустили сервер. Спасибо
2. Я только что обновил описание, пожалуйста, посмотрите
3. Та же проблема на Android.
Ответ №1:
К сожалению, в файле образца configuration.yml
, поставляемом с Realm Object Server, есть ошибка, которую, как я подозреваю, вы столкнулись. providers:
Раздел в файле конфигурации должен находиться под auth:
разделом (а не внутри network:
раздела, где он находится в отправленном файле). Исправление заключается в том, чтобы просто переместить соответствующую конфигурацию провайдеров для работы под auth:
ключом.
У нас есть готовое исправление для этой ошибки, которое станет частью следующего выпуска Realm Object Server.
Вот пример фрагмента, показывающий полный auth:
раздел с исправлением:
# Realm Object Server Configuration
#
# For each possible setting, the commented out values are the default values
# unless another default is mentioned explicitly.
#
# Paths specified in this file can be either absolute or relative.
# Relative paths are relative to the current working directory.
auth:
## The path to the public and private keys (in PEM format) that will be used
## to validate identity tokens sent by clients.
## These configuration options are MANDATORY.
public_key_path: /etc/realm/token-signature.pub
private_key_path: /etc/realm/token-signature.key
providers:
## Providers of authentication tokens. Each provider has a configuration
## object associated with it. If a provider is included here and its
## configuration is valid, it will be enabled.
## Possible providers: cloudkit, debug, facebook, realm, password
## Providers 'realm' and 'password' are always enabled:
## - The 'realm' provider is used to derive access tokens from a refresh token.
## - The 'password' provider is required for the dashboard to work. It supports
## authentication through username/password and uses a PBKDF2 implementation.
## This enables authentication via a Google Sign-In access token for a
## specific app.
google:
## The client ID as retrieved when setting up the app in the Google
## Developer Console.
clientId: '<SOME-HASH-HERE>.apps.googleusercontent.com'
## This enables authentication via a Facebook access token for a specific app.
## This provider needs no configuration (uncommenting the next line enables it).
facebook: {}
Комментарии:
1. Не могли бы вы предоставить фрагмент того, как должен выглядеть файл конфигурации?
2. Я только что попробовал, перезапустил систему, но это исправление не помогло. Ошибка остается прежней
3. Кстати, чтобы применить любые изменения, внесенные в пользовательские средства аутентификации, перезапустите ROS. См . realm.io/docs/realm-object-server/#running-the-server