IntentFilter无法使用给定的HTTP URL

问题描述 投票:0回答:1

我正在尝试向我的Xamarin.Forms应用添加“使用LinkedIn登录”按钮。我正在将Xamarin.AuthCustom Tabs方法结合使用。

这意味着为了获得登录+授权的结果,我需要使用IntentFilter。由于我已复制from here,因此使用Google的身份验证正在运行,但是IntentFilter并未拦截使用LinkedIn的身份验证。

我不确定是怎么了。重定向URL可能不正确,或者我的IntentFilter有问题。

我尝试使用其他URL,甚至localhost:PORT都没有成功。

IntentFilter:

[Activity(Label = "LinkedInInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataSchemes = new[] { "http", "https" }, DataHost = "www.linkedin.com", DataPath = "/Act/Callback")]
public class LinkedInInterceptorActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        //Convert Android.Net.Url to Uri
        var uri = new Uri(Intent.Data.ToString());

        //Load redirectUrl page
        Global.Authenticator.OnPageLoading(uri);

        var intent = new Intent(this, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
        StartActivity(intent);

        Finish();
    }
}

LinkedIn配置:

RedirectUrls

c# xamarin xamarin.android intentfilter
1个回答
0
投票

我认为您的授权URL不正确。您正在使用“ / Act / Callback”的应该是“ / oauth / v2 / authorization”

我不熟悉“自定义标签”方法,但是我想使用OAuth进行身份验证需要相同的基本步骤。

您的重定向URL应该是用户在其站点上进行身份验证后,LinkedIn回叫的位置。可能类似于“ http://www.yoursite.com/oauth/v2/linkedin”。您的应用程序将需要配置为在该地址上侦听传入的http或https连接。这通常是一个Web服务器,但是在C#上,HttpListener也可以工作。 Xamarin.Auth可能已经为您内置了此功能,但是我不熟悉OAuth的确切实现。 (您说它适用于Google,所以我认为它在一定程度上可以做到)

如果您的应用跨多个设备独立运行,则可能无法将所有设备地址添加到允许的重定向列表中。在这种情况下,您将必须设置与此类似的应用程序:

应用程序通知yoursite.com正在等待验证。应用程序将用户定向到LinkedIn进行身份验证。 LinkedIn会回调yoursite.com(这是允许的重定向)并发送身份验证结果。 yoursite.com将认证结果中继到正在等待认证结果的应用程序。

无论OAuth流似乎比您想的还多。参见:

https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context

https://docs.microsoft.com/en-us/linkedin/shared/authentication/client-credentials-flow?context=linkedin/context

有关如何使用OAuth连接到LinkedIn的特定信息。

© www.soinside.com 2019 - 2024. All rights reserved.