好的,所以我试图使用Xamarin.Auth在Xamarin.iOS上做一个非常基本的身份验证,并得到一个错误:“应用程序配置不允许给定的URL。:应用程序的设置不允许一个或多个给定的URL。它必须匹配网站URL或画布URL,或者域名必须是应用程序的某个域的子域。”
我已经在谷歌上搜索了一段时间,看起来你可能再也不能在Facebook上使用Xam.Auth了--这似乎不太可能.
下面是我的示例代码(sans我的FB应用程序Id) --您会注意到它实际上是Xam示例代码的副本:
using System;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Threading.Tasks;
using MonoTouch.Dialog;
#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif
namespace Xamarin.Auth.Sample.iOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
void LoginToFacebook (bool allowCancel)
{
var auth = new OAuth2Authenticator (
clientId: "SOME_ID",
scope: "",
authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));
auth.AllowCancel = allowCancel;
// If authorization succeeds or is canceled, .Completed will be fired.
auth.Completed += (s, e) =>
{
// We presented the UI, so it's up to us to dismiss it.
dialog.DismissViewController (true, null);
if (!e.IsAuthenticated) {
facebookStatus.Caption = "Not authorized";
dialog.ReloadData();
return;
}
// Now that we're logged in, make a OAuth2 request to get the user's info.
var request = new OAuth2Request("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
request.GetResponseAsync().ContinueWith (t => {
if (t.IsFaulted)
facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
else if (t.IsCanceled)
facebookStatus.Caption = "Canceled";
else
{
var obj = JsonValue.Parse(t.Result.GetResponseText());
facebookStatus.Caption = "Logged in as " + obj["name"];
}
dialog.ReloadData();
}, uiScheduler);
};
UIViewController vc = auth.GetUI ();
dialog.PresentViewController (vc, true, null);
}
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
facebook = new Section ("Facebook");
facebook.Add (new StyledStringElement("Log in", () => LoginToFacebook (true)));
facebook.Add (new StyledStringElement("Log in (no cancel)", () => LoginToFacebook (false)));
facebook.Add (facebookStatus = new StringElement (String.Empty));
dialog = new DialogViewController (new RootElement ("Xamarin.Auth Sample") {
facebook,
});
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UINavigationController (dialog);
window.MakeKeyAndVisible ();
return true;
}
private readonly TaskScheduler uiScheduler =
TaskScheduler.FromCurrentSynchronizationContext();
UIWindow window;
DialogViewController dialog;
Section facebook;
StringElement facebookStatus;
// This is the main entry point of the application.
static void Main (string[] args)
{
UIApplication.Main (args, null, "AppDelegate");
}
}
}发布于 2014-10-19 10:40:22
您是否添加了URL "http://www.facebook.com/connect/login_success.html"作为一个有效的重定向URL到您的应用程序的配置在Facebook上?
我希望在您拥有的域中有一个URL,这看起来像从示例中复制的东西。
发布于 2017-05-12 08:40:08
redirect_url依赖于服务器端定义的服务提供者和应用程序类型(谷歌称其为控制台)。基本上有两种类型的应用程序:服务器-AKA和移动-AKA-安装。服务器-AKA几乎总是使用授权代码授予,而Mobile安装可以使用隐式授权流或修改授权代码授予流,其中没有发送client_secret (设备上不存在),因为它被认为是不安全的。服务器-AKA用于服务器(web应用程序),恶意用户获取client_secret要复杂得多。服务器可以打开任何网页(https方案)--通常是同一主机上的某个页面/路由/路径,但它可能是另外一些东西。
Xamarin.Auth使用这种方法在浏览器中打开某些页面并分析url以获取返回的OAuth数据。它不能解析https://localhost什么是有效的redirect_url,但是移动应用程序没有web服务器来具有本地主机可加载的页面。此外,Xamarin.Auth永远无法与fb22145312这样的定制计划合作。
这一点随着版本1.4的改变而改变,该版本增加了对谷歌OAuth认证所要求的自定义方案的支持--AKA--已安装的应用程序,其中禁止嵌入式WebViews,移动应用必须使用所谓的本地UI --在Android上和iOS SFSafariViewController上。他们需要定制的方案,深度AKA-应用程序链接,以便redirect_url可以被拦截的移动应用程序注册该方案。
因此,如果您的应用程序是web应用程序,那么您可以为redirect_url使用https方案,但是如果您选择了Android或iOS应用程序,那么提供者(在本例中是Facebook)将为必须使用的应用程序生成方案。
提供者有不同的方法来检查请求的有效性,并且似乎您的应用程序在服务器端的其他数据(网站,有效的Urls不同于您的redirect_url)。这解释了您获得的错误消息的最后一部分。
https://stackoverflow.com/questions/26435598
复制相似问题