- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 Firebase 平台的用户实现 oAuth 登录。
除非用户已 禁用跨域 cookie,否则一切正常。
这就是我所做的。
state
cookie 并将用户重定向到 oAuth 提供商。 在上面的步骤 3 中,如果用户在浏览器中禁用了跨域方 cookie,则该函数无法读取任何 cookie。这两个函数都位于同一域中,如下面的屏幕截图所示。
有什么办法可以解决这个问题吗?我的方法是否做错了什么?
我不明白为什么这两个函数被视为跨域。
更新以包含更多信息
请求:
Request URL: https://europe-west2-quantified-self-io.cloudfunctions.net/authRedirect
Request Method: GET
Status Code: 302
Remote Address: [2a00:1450:4007:811::200e]:443
Referrer Policy: no-referrer-when-downgrade
请求 header
:authority: europe-west2-quantified-self-io.cloudfunctions.net
:method: GET
:path: /authRedirect
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: en-GB,en-US;q=0.9,en;q=0.8
cookie: signInWithService=false; state=877798d3672e7d6fa9588b03f1e26794f4ede3a0
dnt: 1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
响应 header
alt-svc: quic=":443"; ma=2592000; v="46,43,39"
cache-control: private
content-encoding: gzip
content-length: 218
content-type: text/html; charset=utf-8
date: Sat, 03 Aug 2019 08:55:18 GMT
function-execution-id: c8rjc7xnvoy8
location: https://cloudapi-oauth.suunto.com/oauth/authorize?response_type=code&client_id=xxx&redirect_uri=&scope=workout&state=1c8073866d1ffaacf2d4709090ad099872718afa
server: Google Frontend
set-cookie: state=1c8073866d1ffaacf2d4709090ad099872718afa; Max-Age=3600; Path=/; Expires=Sat, 03 Aug 2019 09:55:18 GMT; HttpOnly; Secure
set-cookie: signInWithService=false; Max-Age=3600; Path=/; Expires=Sat, 03 Aug 2019 09:55:18 GMT; HttpOnly; Secure
status: 302
vary: Accept
x-cloud-trace-context: 99a93680a17770f848f200a9e729b122;o=1
x-powered-by: Express
之后,一旦用户从服务返回,他就根据解析 cookie 的代码(或处理该cookie的函数)进行身份验证:
export const authToken = functions.region('europe-west2').https.onRequest(async (req, res) => {
const oauth2 = suuntoAppAuth();
cookieParser()(req, res, async () => {
try {
const currentDate = new Date();
const signInWithService = req.cookies.signInWithService === 'true';
console.log('Should sign in:', signInWithService);
console.log('Received verification state:', req.cookies.state);
console.log('Received state:', req.query.state);
if (!req.cookies.state) {
throw new Error('State cookie not set or expired. Maybe you took too long to authorize. Please try again.');
} else if (req.cookies.state !== req.query.state) {
throw new Error('State validation failed');
}
console.log('Received auth code:', req.query.code);
const results = await oauth2.authorizationCode.getToken({
code: req.query.code,
redirect_uri: determineRedirectURI(req), // @todo fix,
});
// console.log('Auth code exchange result received:', results);
// We have an access token and the user identity now.
const accessToken = results.access_token;
const suuntoAppUserName = results.user;
// Create a Firebase account and get the Custom Auth Token.
let firebaseToken;
if (signInWithService) {
firebaseToken = await createFirebaseAccount(suuntoAppUserName, accessToken);
}
return res.jsonp({
firebaseAuthToken: firebaseToken,
serviceAuthResponse: <ServiceTokenInterface>{
accessToken: results.access_token,
refreshToken: results.refresh_token,
tokenType: results.token_type,
expiresAt: currentDate.getTime() + (results.expires_in * 1000),
scope: results.scope,
userName: results.user,
dateCreated: currentDate.getTime(),
dateRefreshed: currentDate.getTime(),
},
serviceName: ServiceNames.SuuntoApp
});
} catch (error) {
return res.jsonp({
error: error.toString(),
});
}
});
});
上面的代码没有找到名为state
的cookie
所以这里失败了
if (!req.cookies.state) {
throw new Error('State cookie not set or expired. Maybe you took too long to authorize. Please try again.');
} else if (req.cookies.state !== req.query.state) {
throw new Error('State validation failed');
}
在这里进行了更多搜索,获得了更多信息。
我基于https://github.com/firebase/functions-samples/tree/master/instagram-auth的例子
看起来其他用户也遇到了同样的问题https://github.com/firebase/functions-samples/issues/569
我也打开了这个问题https://github.com/firebase/firebase-functions/issues/544
最佳答案
您的响应显示 state
和 signInWithService
cookie 的 Set-Cookie header ,不带 domain
属性:
set-cookie: state=1c8073866d1ffaacf2d4709090ad099872718afa; Max-Age=3600; Path=/; Expires=Sat, 03 Aug 2019 09:55:18 GMT; HttpOnly; Secure
set-cookie: signInWithService=false; Max-Age=3600; Path=/; Expires=Sat, 03 Aug 2019 09:55:18 GMT; HttpOnly; Secure
没有域的 Set-Cookie 意味着 cookie 在返回服务器的过程中发生的情况取决于浏览器。 “默认”、符合规范的行为:浏览器将获取服务 URL 的 FQDN 并将其与 cookie 关联。 RFC6265:
Unless the cookie's attributes indicate otherwise, the cookie isreturned only to the origin server (and not, for example, to anysubdomains)...If the server omits the Domain attribute, the user agentwill return the cookie only to the origin server.
当浏览器决定是否接受来自 HTTP 服务的 cookie 时,决策标准之一是该 cookie 是第一方还是第三方。派对::
europe-west2-quantified-self-io.cloudfunctions.net/authRedirect
的调用,则位于 https ://europe-west2-quantified-self-io.cloudfunctions.net/...
europe-west2-quantified-self-io.cloudfunctions.net/authRedirect
的调用,则位于 https ://some.domain.app.com/...
在您的情况下,您的“父”应用/页面的 FQDN 可能与 europe-west2-quantified-self-io.cloudfunctions.net
不同,因此这些 Cookie 被标记为第三方。正如您所发现的,用户可以选择阻止第三方 cookie。截至 2019 年 8 月,Firefox 和 Safari 默认阻止第 3 方 cookie。大多数(如果不是全部)广告拦截器和类似的扩展程序也会阻止它们。这将导致浏览器简单地忽略来自 europe-west2-quantified-self-io.cloudfunctions.net/authRedirect
的 HTTP 响应中的 Set-Cookie header 。该 Cookie 不会发送回位于 europe-west2-quantified-self-io.cloudfunctions.net/authToken
的第二个 Firebase 函数,因为客户端上不存在该 cookie。
您的选择:
/authRedirect
FB 函数,解析响应(包括通过 Set-Cookie header 的 cookie),然后将响应(包括 cookie)写回通过 document.cookie
发送到浏览器。在这种情况下,cookie 是第一方的。cloudapi-oauth.suunto.com
执行的 oAuth 授权授予流程,因为授权服务器不需要 Cookie。您关注了instagram-auth推荐此流程的示例When clicking the Sign in with Instagram button a popup is shown whichredirects users to the redirect Function URL.
The redirect Function then redirects the user to the Instagram OAuth2.0 consent screen where (the first time only) the user will have to grant approval. Also the
state
cookie is set on the client with thevalue of thestate
URL query parameter to check against later on.
针对 state
查询参数的检查基于 implementation best practice对于 oAuth 客户端,当授权服务器不支持 PKCE 扩展(cloudapi-oauth.suunto.com
不支持)时:
Clients MUST prevent CSRF. One-time use CSRF tokens carried in the"state" parameter, which are securely bound to the user agent, SHOULDbe used for that purpose. If PKCE [RFC7636] is used by the client andthe authorization server supports PKCE, clients MAY opt to not use"state" for CSRF protection, as such protection is provided by PKCE.In this case, "state" MAY be used again for its original purpose,namely transporting data about the application state of the client
关键短语安全地绑定(bind)到用户代理。对于网络应用程序来说,cookie 是实现此绑定(bind)的一个不错的选择,但它不是唯一的选择。您可以将状态值粘贴到本地或 session 存储中,单页应用程序在实践中正是这样做的。如果您想生活在云端,您可以将状态
保存在云存储或同等设备中...但您必须创建一个唯一标识您的客户端和的 key 这个特定的 HTTP 请求。并非不可能,但对于一个简单的场景来说可能有点过分了。
关于firebase - 在同一域上使用 firebase 函数的 oAuth 的跨域状态 cookie 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57253593/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!