我正在使用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
}
…
}
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误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
}
Run Code Online (Sandbox Code Playgroud)
这是请求正文:
{
"provider":"google",
"app_id":"com.blabla.bla-bla-bla",
"data":"<SOME-HASH-HERE>.apps.googleusercontent.com"
}
Run Code Online (Sandbox Code Playgroud)
我从官方文档中的示例中获取了auth代码,并且我正在使用最新的Realm框架.
我还使用Facebook检查了身份验证,但它也出现了同样的错误.
我查了服务器configuration.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: {}
Run Code Online (Sandbox Code Playgroud)
在我对该文件进行更改后,我打了电话
sudo service realm-object-server restart
Run Code Online (Sandbox Code Playgroud)
而且只是为了确保我也重启系统.
遗憾的是,configuration.ymlRealm Object Server附带的示例文件中存在一个错误,我怀疑您正在使用它.在providers:配置文件中的部分应该生活在该auth:节(而不是里面network:它生活的地方在发货文件部分).修复方法是简单地将相关提供程序配置移动到auth:密钥下.
我们已经准备好了这个bug,它将成为下一个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: {}
Run Code Online (Sandbox Code Playgroud)