我正在尝试连接到没有SSL的IdentityServer(V4)但是在我的Xamarin iOS应用程序上发生崩溃。
码:
OidcClient _client;
AuthorizeState _state;
SafariServices.SFAuthenticationSession _session;
public ViewController(IntPtr handle) : base(handle)
{
var options = new OidcClientOptions
{
Authority = "http://auth.xxxx.be",
ClientId = "iosClient",
Scope = "openid email xxx",
RedirectUri = "xxxApp://callback",
ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
};
_client = new OidcClient(options);
}
执行代码时,我收到以下错误:
Error loading discovery document: Error connecting to
http://auth.xxxx.be/.well-known/openid-configuration: HTTPS required
我尝试使用以下行允许非https请求
<plist version="1.0">
<dict>
...
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
</dict>
</dict>
</plist>
但这没有效果。可能是因为OidcClient使用他自己的方法连接到这个Web应用程序。
在使用SSL的情况下,这不是问题,但我想节省一些在Azure上运行我的网站的成本(= SSL支持的成本更高)。
我正在使用iOS 11运行最新的Xamarin / Visual Studio。
你可以使用浏览器访问你的配置吗? http://auth.xxxx.be/.well-known/openid-configuration
如果没有,可能是您的服务器设置不正确。如果它不是你的服务器,这应该工作:
_options = new OidcClientOptions()
{
Authority = "your authority",
ClientId = clientId,
ClientSecret = "secret",
Scope = "your scopes",
RedirectUri = "redirectUrl",
ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
Policy = new Policy()
{
Discovery = new DiscoveryPolicy() { RequireHttps = false }
}
};
为避免崩溃,请将其包装在try catch中并进行相应的计划。