当前位置: 首页 > 知识库问答 >
问题:

如何打开然后自动关闭的OAuth页面在Chrome在Android?

邓驰
2023-03-14

[我在Xamarin中这样做,但我怀疑答案并不重要,因为Xamarin公开的API或多或少与本机Java相同]

我正在尝试学习OAuth并实现授权流(没有隐式授权)。这包括打开浏览器,进行身份验证,然后不进行密钥交换。你会觉得这很容易。下面是我的资料。

public void Authenticate()
{
    var sb = new StringBuilder();
    sb.Append("https://accounts.google.com/o/oauth2/v2/auth");
    sb.Append("?client_id=<MY ID HERE>");
    sb.Append("&response_type=code");
    sb.Append("&scope=openid%20email");
    sb.Append("&redirect_uri=<MY PACKAGE NAME HERE>:/oauth2redirect");

    var url = sb.ToString();

    var uri = Android.Net.Uri.Parse("googlechrome://navigate?url=" + url);
    try
    {
        System.Diagnostics.Debug.WriteLine(uri.ToString());

        Intent i = new Intent(Intent.ActionView, uri);
        i.AddFlags(ActivityFlags.NewTask);
        i.AddFlags(ActivityFlags.SingleTop);
        i.AddFlags(ActivityFlags.ClearTop);
        i.AddFlags(ActivityFlags.NoHistory);
        Android.App.Application.Context.StartActivity(i);
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
    }
}

共有1个答案

卓雅达
2023-03-14

您使用的是chrome,而不是chrome自定义选项卡:

示例:

var sb = new StringBuilder()
    .Append("https://accounts.google.com/o/oauth2/v2/auth")
    .Append($"?client_id={clientID}")
    .Append("&response_type=code")
    .Append("&scope=https://www.googleapis.com/auth/drive")
    .Append($"&redirect_uri={PackageName}:/SushiRedirect");

var builder = new CustomTabsIntent.Builder(GetSession())
    .SetToolbarColor(Color.ParseColor(TOOLBAR_COLOR)).SetShowTitle(true)
    .SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left)
    .SetExitAnimations(this, Resource.Animation.slide_in_left, Resource.Animation.slide_out_right)
    .SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back));
var customTabsIntent = builder.Build();
CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent);
customTabsIntent.LaunchUrl(this, Uri.Parse(sb.ToString()));

并将意图筛选器添加到launchmode.singletask活动中,以捕获重定向并“关闭”shared选项卡。您的auth代码将位于Intent数据(Intent?.data?.tostring()):

[Activity(Label = "CustomTabsClient.Application", MainLauncher = true, Icon = "@drawable/ic_launcher", LaunchMode = LaunchMode.SingleTask)]
[IntentFilter(
    new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "com.sushhangover.customtabsclient.example", DataPath = "/SushiRedirect")]

https://github.com/sushihangover/sushihangover.googlechrome.customtabs.shared

 类似资料:
  • 在页面中收集各种链接后,我点击这些链接并将其收集成汤。现在的问题是,链接在新标签中打开。我想在代码打开新标签中的下一个链接之前关闭标签。下面是代码片段。收完汤后,请帮我把每个标签关上。 我用python 3.7硒铬驱动

  • 问题内容: 题 我想启动Chrome网络浏览器作为访问特定网站的过程,然后等待它关闭。 一种特殊情况是浏览器可能已经打开并正在运行,因为用户可能已经访问过某些网站。 在这种情况下,浏览器可能会在现有窗口中打开一个新选项卡,并且新启动的过程将立即终止。这不应该使我的等待过程感到困惑:要么,我想要一个新的浏览器窗口(如果可以通过命令行参数强制执行),然后等待直到将其关闭,或者保留现有的浏览器窗口,并等

  • 问题内容: 我正在尝试使用$ log.debug(“ Foo”)。如何将其关闭。我在任何地方都找不到样品。我认为它需要在配置中设置,但我似乎也无法使其正常工作。 哪里设置开关? 问题答案: $ logProvider.debugEnabled(true) 仅在AngularJs 1.1.2或更高版本中可用。 https://github.com/angular/angular.js/pull/16

  • 我更换了笔记本电脑,克隆了项目的存储库,快速安装了一个纱线,看起来与主分支上的有很大的不同,但我没有费心,因为可能只是因为节点版本不同。 现在,每次我点击一个文本输入,键盘只会在android上立即打开和关闭。我在这里附上了一个快速录音。尝试了一些解决方案,看起来像是在AndroidManifest中将android:WindowsofInputMode从adjustResize切换到adjust

  • 问题内容: 我每天都在使用脚本。这是一个无头的Chrome,每5分钟检查一次站点,然后突然打开devmode,而我似乎无法关闭它。这是我的脚本: 输出为: 每次连接到新站点时,它还会显示F12开发人员控制台信息。:C 问题答案: 我终于解决了:D 这就是全部。

  • 未创建会话:此版本的ChromeDriver仅支持Chrome版本83构建信息:版本:“3.141.59”,修订版:“E82BE7D358”,时间:“2018-11-14T08:17:03”系统信息:主机:“Laptop-GRB5533T”,IP:“192.168.43.182”,OS.Name:“Windows 10”,OS.arch:“AMD64”,OS.version:“10.0”,java