IOS提示符上的IdentityServer4和OIDClient

IOS提示符上的IdentityServer4和OIDClient,identityserver4,identitymodel,Identityserver4,Identitymodel,我有IDS4和一个Xamarin.Forms应用程序,除了一个小问题外,其他都可以正常工作。每次iOS应用程序访问IDP服务器时,它都会首先给我以下提示: “AppName”要使用“”登录 这允许应用程序和网站共享有关您的信息 这是什么原因造成的 我使用IdentityModel.OIDClient2时出现此错误。请看原因。其要点如下: 原因 这是在iOS 11中添加到SFAuthenticationSession的系统对话框。它由AppAuth中的以下代码触发: SFAuthenticatio

我有IDS4和一个Xamarin.Forms应用程序,除了一个小问题外,其他都可以正常工作。每次iOS应用程序访问IDP服务器时,它都会首先给我以下提示:

“AppName”要使用“”登录 这允许应用程序和网站共享有关您的信息

这是什么原因造成的


我使用IdentityModel.OIDClient2时出现此错误。请看原因。其要点如下:

原因 这是在iOS 11中添加到
SFAuthenticationSession
的系统对话框。它由AppAuth中的以下代码触发:

SFAuthenticationSession* authenticationVC = 
 [[SFAuthenticationSession alloc] initWithURL:requestURL 
                            callbackURLScheme:redirectScheme 
                            completionHandler:^(NSURL * _Nullable callbackURL, 
                                                NSError * _Nullable error) { 
除了不使用
SFAuthenticationSession
这意味着您失去了单点登录,这更糟糕,没有办法摆脱该对话框

通过使用MLeech提到的方法,我最终使用了SFSafariViewController而不是SFAuthenticationSession

解决方案 这基本上意味着将这些行添加到AppDelegate.cs

 public override UIWindow Window
    {
        get;
        set;
    }

    public static Action<string> CallbackHandler { get; set; }

    public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        CallbackHandler(url.AbsoluteString);
        CallbackHandler = null;

        return true;
    }
公共覆盖窗口
{
得到;
设置
}
公共静态操作回调处理程序{get;set;}
公共覆盖bool OpenUrl(UIApplication应用程序、NSUrl url、string sourceApplication、NSObject注释)
{
CallbackHandler(url.AbsoluteString);
CallbackHandler=null;
返回true;
}
然后将此代码用于SFAuthenticationSessionBrowser.cs

public class SFAuthenticationSessionBrowser : IBrowser
{
    public Task<BrowserResult> InvokeAsync(BrowserOptions options)
    {
        var task = new TaskCompletionSource<BrowserResult>();

        var safari = new SFSafariViewController(new NSUrl(options.StartUrl));

        AppDelegate.CallbackHandler = async url =>
        {
            await safari.DismissViewControllerAsync(true);
            task.SetResult(new BrowserResult()
            {
                Response = url
            });
        };

        // https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service
        var window = UIApplication.SharedApplication.KeyWindow;
        var vc = window.RootViewController;
        while (vc.PresentedViewController != null)
        {
            vc = vc.PresentedViewController;
        }
        vc.PresentViewController(safari, true, null);

        return task.Task;
    }
}
公共类SFAuthenticationSessionBrowser:IBrowser
{
公共任务InvokeAsync(浏览选项)
{
var task=new TaskCompletionSource();
var safari=新的SFSafariViewController(新的NSUrl(options.StartUrl));
AppDelegate.CallbackHandler=异步url=>
{
等待safari.DismissViewControllerAsync(true);
task.SetResult(新的BrowserResult()
{
响应=url
});
};
// https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service
var window=UIApplication.SharedApplication.KeyWindow;
var vc=window.RootViewController;
while(vc.PresentedViewController!=null)
{
vc=vc.PresentedViewController;
}
PresentViewController(safari,true,null);
返回任务。任务;
}
}

我使用IdentityModel.OIDCClient 2时出现此错误。请看原因。其要点如下:

原因 这是在iOS 11中添加到
SFAuthenticationSession
的系统对话框。它由AppAuth中的以下代码触发:

SFAuthenticationSession* authenticationVC = 
 [[SFAuthenticationSession alloc] initWithURL:requestURL 
                            callbackURLScheme:redirectScheme 
                            completionHandler:^(NSURL * _Nullable callbackURL, 
                                                NSError * _Nullable error) { 
除了不使用
SFAuthenticationSession
这意味着您失去了单点登录,这更糟糕,没有办法摆脱该对话框

通过使用MLeech提到的方法,我最终使用了SFSafariViewController而不是SFAuthenticationSession

解决方案 这基本上意味着将这些行添加到AppDelegate.cs

 public override UIWindow Window
    {
        get;
        set;
    }

    public static Action<string> CallbackHandler { get; set; }

    public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        CallbackHandler(url.AbsoluteString);
        CallbackHandler = null;

        return true;
    }
公共覆盖窗口
{
得到;
设置
}
公共静态操作回调处理程序{get;set;}
公共覆盖bool OpenUrl(UIApplication应用程序、NSUrl url、string sourceApplication、NSObject注释)
{
CallbackHandler(url.AbsoluteString);
CallbackHandler=null;
返回true;
}
然后将此代码用于SFAuthenticationSessionBrowser.cs

public class SFAuthenticationSessionBrowser : IBrowser
{
    public Task<BrowserResult> InvokeAsync(BrowserOptions options)
    {
        var task = new TaskCompletionSource<BrowserResult>();

        var safari = new SFSafariViewController(new NSUrl(options.StartUrl));

        AppDelegate.CallbackHandler = async url =>
        {
            await safari.DismissViewControllerAsync(true);
            task.SetResult(new BrowserResult()
            {
                Response = url
            });
        };

        // https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service
        var window = UIApplication.SharedApplication.KeyWindow;
        var vc = window.RootViewController;
        while (vc.PresentedViewController != null)
        {
            vc = vc.PresentedViewController;
        }
        vc.PresentViewController(safari, true, null);

        return task.Task;
    }
}
公共类SFAuthenticationSessionBrowser:IBrowser
{
公共任务InvokeAsync(浏览选项)
{
var task=new TaskCompletionSource();
var safari=新的SFSafariViewController(新的NSUrl(options.StartUrl));
AppDelegate.CallbackHandler=异步url=>
{
等待safari.DismissViewControllerAsync(true);
task.SetResult(新的BrowserResult()
{
响应=url
});
};
// https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service
var window=UIApplication.SharedApplication.KeyWindow;
var vc=window.RootViewController;
while(vc.PresentedViewController!=null)
{
vc=vc.PresentedViewController;
}
PresentViewController(safari,true,null);
返回任务。任务;
}
}

是否提供http://或https://url?是否提供http://或https://url?是否尝试在应用程序中打开OIDC客户端或重定向到外部浏览器?@johnny5 OIDC客户端在Xamarin Forms应用程序中启动,然后通过iOS浏览器启动IDP服务器的MVC登录页面,但不确定是哪个页面。成功登录IDP服务器后,您将通过注册的方案名称重定向回应用程序。。。。这是我的理解。难道不是出于设计,如果你在应用程序中被重定向,你将无法验证idp不是网络钓鱼吗site@johnny5这个问题现在已经解决了,所以我不担心它。上面列出了我提供的决议。如果解决方案有问题,请告诉我。您是想在应用程序中打开OIDC客户端,还是重定向到外部浏览器?@johnny5 OIDC客户端在Xamarin Forms应用程序中启动,然后通过iOS浏览器启动IDP服务器的MVC登录页,但不确定是哪一个。成功登录IDP服务器后,您将通过注册的方案名称重定向回应用程序。。。。这是我的理解。难道不是出于设计,如果你在应用程序中被重定向,你将无法验证idp不是网络钓鱼吗site@johnny5这个问题现在已经解决了,所以我不担心它。上面列出了我提供的决议。如果决议有问题,请告诉我。