- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 WebView 将我的响应式网站变成原生应用。几乎一切似乎都在工作,但我无法工作的一件事是我的“使用 Facebook 登录”和“使用 Google 登录”按钮。顺便说一句,Google One Tap 登录工作正常(在 WebView 应用程序在不同页面(即 Gmail)上登录到 Google 之后),但“使用 Facebook 登录”和“使用 Google 登录”按钮不起作用。请注意,我实际上已经正确配置了我的 Intent (即任何带有我的域名的 returnURL 或 callbackURL 将被调用,仍将通过应用程序调用),但我相信来自 Google 和 Facebook 的这些登录 API 不会返回用户返回任何 returnURL,而只是将他们的结果传递回最初打开登录弹出窗口的 javascript。
问题如下(我认为):起初,两个按钮都在单独的浏览器窗口(Chrome)中打开了链接。当我完成登录过程(使用 Google 或 Facebook)时,此浏览器窗口会自动关闭,但不会向我的应用程序返回任何内容(因此,我的应用程序不知道用户已完成 OAuth 过程)。所以我决定设置 webSettings.setSupportMultipleWindows(false)。这至少解决了我与 Instagram API 的问题(因为它也不起作用),并且它也确实使 Google 和 Facebook 身份验证窗口现在在应用程序中打开(所以我认为我更接近于将其用于工作),但问题是,OAuth 流程的返回数据/结果仍然没有返回到我的应用程序。事实上,Facebook 登录屏幕在完成后设法完全关闭我的应用程序(我猜 window.close() 也会影响我的 WebView 应用程序,或类似的东西)。另一方面,对于 Google,登录后页面保持白色。按返回键可以让我返回到我的应用程序的登录屏幕。
以下是正在发生的事情的示例:
Facebook :
Google(第一次,登录过程正常,但完成登录后,我们最终得到如下相同的白页):
Google(此后每次,一旦您登录到 Google):
在我的应用程序的网站版本中处理响应的 javascript 一切正常!它捕获对 Google 或 Facebook 的 OAuth 调用的结果并处理返回的电子邮件地址和 Google/Facebook ID,然后让用户登录到我的应用程序。
我的问题可能与: Android Google login not working inside WebView
但我无法让它工作。如果有人对这种 WebView 技术有更好的理解,或者知道如何将该主题中提到的解决方案应用于我的情况,将不胜感激任何帮助!
我还读过:Google sign in not working android webview app
该主题中的几个人表示我必须重写弹出窗口处理,但我不知道该怎么做...
这是我的 MainActivity 文件:
webView.setWebViewClient(new MyWebViewClient() {
private Handler notificationHandler;
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String url) {
if (Config.FALLBACK_USE_LOCAL_HTML_FOLDER_IF_OFFLINE) {
loadLocal(INDEX_FILE);
} else {
webView.setVisibility(View.GONE);
offlineLayout.setVisibility(View.VISIBLE);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Basic Overriding part here (1/2)
if (url.startsWith("mailto:")) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)));
return true;
}
if (url.startsWith("share:") || url.contains("api.whatsapp.com")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("whatsapp:")) {
Intent i = new Intent();
i.setPackage("com.whatsapp");
i.setAction(Intent.ACTION_SEND);
i.setType("text/plain");
startActivity(i);
return true;
}
if (url.startsWith("geo:") || url.contains("maps:")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("market:")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("maps.app.goo.gl")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.contains("maps.google.com")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("intent:")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("tel:")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("sms:")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (url.startsWith("play.google.com")) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
return true;
}
if (OPEN_SPECIAL_URLS_IN_NEW_TAB) {
WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Log.i(TAG, " data :" + data);
if ((data != null && data.endsWith("#")) || url.startsWith("newtab:")) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimaryDark));
CustomTabsIntent customTabsIntent = builder.build();
String finalUrl = url;
if (url.startsWith("newtab:")) {
finalUrl = url.substring(7);
}
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(finalUrl));
webView.stopLoading();
return false;
}
}
return super.shouldOverrideUrlLoading(view, url);
}
});
webView.getSettings().setSupportMultipleWindows(false);
webView.setWebChromeClient(new MyWebChromeClient() {
private Handler notificationHandler;
@Override
public void onCloseWindow(WebView window) {
super.onCloseWindow(window);
Log.i(TAG, "onCloseWindow url " + window.getUrl());
Log.i(TAG, "onCloseWindow url " + window.getOriginalUrl());
}
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
Bundle extras = getIntent().getExtras();
String URL = null;
if (extras != null) {
URL = extras.getString("ONESIGNAL_URL");
}
if (URL != null && !URL.equalsIgnoreCase("")) {
isNotificationURL = true;
deepLinkingURL = URL;
} else isNotificationURL = false;
Log.i(TAG, " LOG24 " + deepLinkingURL);
if (!OPEN_SPECIAL_URLS_IN_NEW_TAB) {
Log.i(TAG, "if ");
WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Context context = view.getContext();
if (data == null) {
Log.i(TAG, "else true ");
WebView newWebView = new WebView(view.getContext());
newWebView.setWebChromeClient(new MyWebChromeClient());
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
return true;
} else {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
context.startActivity(browserIntent);
}
} else {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimaryDark));
CustomTabsIntent customTabsIntent = builder.build();
WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Log.i("TAG", " data " + data);
String url = "";
WebView newWebView = new WebView(view.getContext());
newWebView.setWebChromeClient(new WebChromeClient());
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
}
Log.i("TAG", " running this main activity ");
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.i(TAG, " onJsalert");
return super.onJsAlert(view, url, message, result);
}
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mUM = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(Intent.createChooser(i, "Upload"), FCR);
}
@SuppressLint("InlinedApi")
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
if (Config.requireStorage && Config.requireCamera) {
String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, perms, FCR);
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, FCR);
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, FCR);
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, FCR);
}
if (mUMA != null) {
mUMA.onReceiveValue(null);
}
mUMA = filePathCallback;
if (Arrays.asList(fileChooserParams.getAcceptTypes()).contains("audio/*")) {
Intent chooserIntent = fileChooserParams.createIntent();
startActivityForResult(chooserIntent, CODE_AUDIO_CHOOSER);
return true;
}
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCM);
} catch (IOException ex) {
Log.e(TAG, "Image file creation failed", ex);
}
if (photoFile != null) {
mCM = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
FileProvider.getUriForFile(MainActivity.this, getPackageName() + ".provider", photoFile));
} else {
takePictureIntent = null;
}
}
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
File videoFile = null;
try {
videoFile = createVideoFile();
takeVideoIntent.putExtra("PhotoPath", mVM);
} catch (IOException ex) {
Log.e(TAG, "Video file creation failed", ex);
}
if (videoFile != null) {
mVM = "file:" + videoFile.getAbsolutePath();
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT,
FileProvider.getUriForFile(MainActivity.this, getPackageName() + ".provider", videoFile));
} else {
takeVideoIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
contentSelectionIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/* video/*");
contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*"});
Intent[] intentArray;
if (takePictureIntent != null && takeVideoIntent != null) {
intentArray = new Intent[]{takePictureIntent, takeVideoIntent};
} else if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else if (takeVideoIntent != null) {
intentArray = new Intent[]{takeVideoIntent};
} else {
intentArray = new Intent[0];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Upload");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, FCR);
}
return true;
}
});
final WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
if (Config.CLEAR_CACHE_ON_STARTUP) {
webSettings.setAppCacheEnabled(false);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
} else {
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowFileAccess(true);
//webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDatabaseEnabled(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (!Config.USER_AGENT.isEmpty()) {
webSettings.setUserAgentString(Config.USER_AGENT);
}
请注意,上面代码中的 Config.VARIABLES 是在配置文件中定义的。我使用的是假用户代理(不包含 wv- 或 webview- 的用户代理),因为许多其他人已经在这些主题中提出了建议(因为这会导致 Google 出现 UserAgent Not Allowed 错误)。此外,OPEN_SPECIAL_URLS_IN_NEW_TAB 设置为 true,正如您从 Facebook 演示中看到的那样,尽管 setSupportMultipleWindows() 被关闭,应用程序仍然可以在应用程序本身之上打开新选项卡(与打开外部浏览器窗口相反) ).任何帮助将不胜感激!!
最佳答案
我也找不到任何方法来修复这个错误。我选择了将 google 登录链接重定向到默认浏览器的解决方案,我的新解决方案是:
//Redirecting google login link:
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith(("https://mywebsite.com/wp-login.php?loginSocial=google")) )) {
view.getContext().startActivity (
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
关于android - Webview 应用程序中的 Google 和 Facebook 登录 (OAuth)(需要覆盖弹出功能吗?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67046681/
我有一个 webapp,它使用 php 服务器和数据库服务器执行大量 ajax 请求。我还创建了一个 iPhone 应用程序和一个 Android 应用程序,直到现在它们一直作为离线应用程序工作。 现
OAuth 的访问 token /刷新 token 流对我来说似乎非常不安全。帮助我更好地理解它。 假设我正在与利用 OAuth 的 API 集成(如 this one )。我有我的访问 token
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: How is oauth 2 different from oauth 1 我知道这两个不向后兼容。但是,既然已经实
我已经看到关于此的其他问题( here 、 here 和 here ),但我对任何解决方案都不满意,所以我再次询问。我正在启动一个 Web 应用程序,它将利用来自多个提供商(Google、Facebo
我知道(在 OAuth 中使用授权代码“授权代码”时),访问 token 的生命周期应该很短,但刷新 token 的生命周期可能很长。 所以我决定为我的项目: 访问 token 生命周期:1 天 刷新
在没有浏览器的情况下,我们可以在手机上的应用程序中使用 OAuth 吗? 如果没有浏览器,用户是否仍然可以批准 token 请求(以便消费者可以继续从服务提供者那里获取 protected 资源)?
用非常简单的术语来说,有人可以解释一下 OAuth 2 和 OAuth 1 之间的区别吗? OAuth 1 现在已经过时了吗?我们应该实现 OAuth 2 吗?我没有看到很多 OAuth 2 的实现;
修改表单例份验证登录过程并不难,因此除了正常的表单例份验证之外,WebClient 对象对由使用 Thinktecture IdentityModel 设置的 Web Api DAL 提供的 api/
我想连接到 LinkedIn 并通过他们的 API 提取一些信息。 LinkedIn API 使用 OAuth 2.0。 我读过的所有关于 OAuth 的文档(无论是在 LinkedIn 的上下文中还
OAuth 与其他身份验证标准的支持范围有多广? 这可能是社区维基的东西,但我还是要问。 我需要投资一些与服务器身份验证相关的东西,而且那里似乎有一些不错的东西。 最佳答案 OAuth 主要用作授权机
我有几个问题... 雅虎和微软 api 是否支持 oAuth 2.0? 如果是,那么主要是什么 应该采取的安全措施 转移时受到照顾 oAuth 1.0 到 oAuth 2.0。 Google API
我已经用谷歌 oAuth 开发了一个应用程序,这工作正常。 我可以登录并访问我的网站。 我的问题是,当我从我的应用程序中注销(注销)时,我删除了所有 session ,但未删除经过身份验证的 cook
我在 Internet 上寻找一些关于此的信息,最后在 RFC 上找到了 Oauth 1.0 协议(protocol):https://www.rfc-editor.org/rfc/rfc5849 您
我正在尝试制作 Google OpenID/OAuth hybrid签到工作。问题是它是一个可安装的网络(所以没有固定域),我也试图让它在我的开发机器上工作 - 所以返回 URL 类似于 http:/
我想构建一个独立与任何身份提供者(如 ADFS、OpenAM、oracle 身份)一起工作的应用程序。我的目的是验证来自任何一个 IDP 的登录用户,这些 IDP 配置为实现我的 SSO。 我不确定
我正在深入研究 Spring OAuth,发现一些相互矛盾的信息。 具体来说,this tutorial声明 /oauth/token 端点在将刷新 token 授予客户端应用程序之前处理用户名和密码
如何通过自定义命令行工具支持三足式 OAuth 工作流? 我想允许我的 CLI 工具的用户上网、登录并在本地缓存 token ,类似于 heroku login。正在做。 最佳答案 你必须扔掉同意屏幕
什么是 oauth 域?是否有任何免费的 oauth 服务?我可以将它用于 StackApps registration 吗? ?我在谷歌上搜索了很多,但找不到答案。 最佳答案 这是redirect_
我需要将我的 Delicious 书签下载到非 Web 应用程序,而无需持续的用户交互。我正在使用 Delicious 的 V2 API(使用 oAuth),但问题是他们的访问 token 似乎在一小
我正在尝试为两台服务器设置一个 nginx 负载均衡器/代理,并在两台服务器上运行 OAuth 身份验证的应用程序。 当 nginx 在端口 80 上运行时,一切都运行良好,但是当我将它放在任何其他端
我是一名优秀的程序员,十分优秀!