这实际上分为许多单独的问题以了解整个过程。
据我了解,JWT 只是将三个 JSON 对象分别编码为 base64。然后 Base64 字符串用句点分隔。这纯粹是为了“更短的消息”目的吗?
其中包括标头、“有效负载”和签名。任何拦截它们的人都可以 100% 读取标头和有效负载。它们只是可以解码为 JSON 并读取的 Base64 字符串。
然后MAGIC:服务器收到无法解码的SIGNATURE。签名实际上是标头、有效负载和密钥的哈希值。因此,服务器获取标头、有效负载和它自己的密钥,并生成哈希值。如果此哈希值与消息附带的签名匹配,则该消息是可信的。如果签名不匹配,则消息无效。
我的这一切有问题吗?这里的两个单独的钥匙在哪里?看来用于加密消息的密钥和用于解密消息的密钥是相同的。这是我问题的根源 - 如果您没有回答其他问题,请帮忙解决这个问题。
除此之外,我想知道我是否正确理解了这个过程?另外,“就公钥达成一致”然后交易此处发生的公钥/私钥“混合”的标准在哪里?我所看到的只是用于编码/解码的相同密钥。但这个协议是什么时候达成的呢?顺便说一句,在 .NET 和 Auth0 的上下文中查看这一点,但总体而言。
如果有人有兴趣稍后看到这个问题,我观看/阅读/使用的随机内容:
JWT 总结:https://scotch.io/tutorials/the-anatomy-of-a-json-web-token
公钥/非对称加密:https://youtu.be/3QnD2c4Xovk
哈希: http: //www.webopedia.com/TERM/H/hashing.html
Base64: http: //en.wikipedia.org/wiki/Base64
我在 Rails 应用程序中使用Auth0进行身份验证。我需要编写一些用于登录和注册的功能测试。我似乎找不到关于如何使用 rspec 和 capybara 执行此操作的具体内容。
尝试按照本要点中解释的方式做一些事情,但它仍然不起作用。如果有人有使用 Auth0 进行 rspec 功能测试的经验,如果您能指导我正确的方向,我将不胜感激。
谢谢!
我的配置
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:auth0] = {
'provider' => 'auth0',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
'image' => 'mock_user_thumbnail_url'
},
'credentials' => {
'token' => 'mock_token',
'secret' => 'mock_secret'
}
}
end
end
# in spec/requests/spec_helper.rb
RSpec.configure do …Run Code Online (Sandbox Code Playgroud) 我有一个 Auth0 客户端,配置了以下回调 URL:
我可以正常登录。
问题是当我导航到应用程序中的某个 URL 时:http://localhost:4200/places。发生的情况如下:
http://localhost:4200/placeshttp://localhost:4200Auth0 是对的,http://localhost:4200/places它不在我允许的回调 URL 列表中,而且我也不希望它出现在其中。我不想列出我的用户可能被踢回登录屏幕的任何 URL。
因此,由于某种原因,发生了一些事情,告诉 Auth0 引用 URL 是http://localhost:4200/places而不是http://localhost:4200,尽管http://localhost:4200实际上是我尝试登录时地址栏中的 URL。
我意识到我可以指定http://localhost:4200为redirectUrl并“修复”问题,但随后我必须redirectUrl在开发、登台和生产方面做出不同的改变。这似乎不是人们通常解决这个问题的方式。
我怎样才能让 Auth0 不尝试将我重定向到/places?
我正在使用优秀的goa包在 Go 中生成我的 API。
但是,我的安全中间件存在问题,当我向控制器提交不记名令牌时,由于“scopes:null”,我收到“授权失败”。我使用 Auth0 进行身份验证,它正在生成不记名令牌。Postman 中的确切错误是:
{"id":"xOUR882s","code":"jwt_security_error","status":401,"detail":"authorization failed: required 'scopes' not present in JWT claim","meta":{"required":["read:meta"],"scopes":null}}
Run Code Online (Sandbox Code Playgroud)
但是,我的令牌确实包含所需的范围read:meta。jwt.io返回以下解码后的承载:
{
"iss": "https://learnlogic.au.auth0.com/",
"sub": "exJMkK7hXX56lrLwoTqna3s0jh7Gq67e@clients",
"aud": "https://api.learn-logic.com",
"exp": 1494855336,
"iat": 1494768936,
"scopes": "read:meta"
}
Run Code Online (Sandbox Code Playgroud)
middleware/jwt.go我希望有人可以帮助我解决原因,因为我真的不明白该项目中发生了什么goa,可以在这里找到。我唯一的想法是 Auth0 格式的承载的某些内容与parseClaimScopes中的功能不兼容middleware/jwt.go,但我不知道是什么。
我有以下main.go代码:
b, err := ioutil.ReadFile("util/jwt.key")
if err != nil {
return
}
block, _ := pem.Decode([]byte(b))
var cert *x509.Certificate
cert, _ = x509.ParseCertificate(block.Bytes)
rsaPublicKey := cert.PublicKey.(*rsa.PublicKey)
fmt.Println(rsaPublicKey.N)
fmt.Println(rsaPublicKey.E) …Run Code Online (Sandbox Code Playgroud) 使用散列路由(例如http://somdomain.com/#/somerouteauth0 )与 Angular 2 一起使用的文档和示例非常稀疏且过时。
有多个问题需要解决:
auth0库监听 URL 片段的变化。不幸的是,angular它会吞掉 URL 片段的更改,因为它认为它正在处理路由。
url 片段以#access_token=...和 Angular 开头,因为 access_token 未注册为路由,因此 Angular 会抛出错误。
即使您注册了一条路线,access_token您也不希望以任何方式将其显示为路线,因此您需要取消导航。
要真正设置它,需要做哪些事情?
我正在尝试创建与 Revolut 的客户端连接。我正在遵循他们的教程,但是我被困在Exchange Authorization Code上。
到目前为止我所做的:
Access is not enabled在我的 API 证书上看到像这样发送访问令牌请求(通过邮递员完成):
curl --request POST \
--url https://sandbox-b2b.revolut.com/api/1.0/auth/token \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Content-Length: 596' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Host: sandbox-b2b.revolut.com' \
--header 'User-Agent: PostmanRuntime/7.20.1' \
--header 'cache-control: no-cache' \
--data 'grant_type=authorization_code&code=oa_sand_xxx&client_id=xxx&client_assertion_type=xxx&client_assertion=xxx …Run Code Online (Sandbox Code Playgroud)我陷入了困境。
我开始使用 NestJS 构建一个良好的老式 REST API todo 服务器。然后我使用这篇文章将 Auth0 添加到其中,您可以使用AuthGuard:
https://auth0.com/blog/developing-a-secure-api-with-nestjs-adding-authorization/
然而,我从来没能让事情正常工作,总是出错401 Unauthorized。这很令人沮丧。
然后我找到了这篇文章:
https://auth0.com/blog/full-stack-typescript-apps-part-1-developing-backend-apis-with-nestjs/
这让我构建了中间件来使用 Auth0 和 JWT 进行身份验证。你瞧,它成功了。
但这感觉不对——我觉得我应该能够利用NestJS 装饰器的优点@UseGuards来完成整个授权工作。AuthGuard
所以我想我的问题有两个:我在使用中间件而不是 NestJS 装饰器方面犹豫不决是错误的吗?有没有人有一个在 NestJS 中使用装饰器的简单有效的例子?
我正在使用这个react-auth-spa.jsx,
/* eslint-disable react/require-default-props */
// src/react-auth0-spa.js
import React, { useState, useEffect, useContext } from 'react';
import PropTypes from 'prop-types';
import createAuth0Client from '@auth0/auth0-spa-js';
const DEFAULT_REDIRECT_CALLBACK = () => {
window.history.replaceState({}, document.title, window.location.pathname);
};
export const Auth0Context = React.createContext();
export const useAuth0 = () => useContext(Auth0Context);
export const Auth0Provider = ({
children,
onRedirectCallback = DEFAULT_REDIRECT_CALLBACK,
...initOptions
}) => {
const [isAuthenticated, setIsAuthenticated] = useState();
const [user, setUser] = useState();
const [auth0Client, setAuth0] = useState();
const [loading, setLoading] = useState(true);
const …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用客户端凭据通过 Swagger UI(由 Swashbuckle.AspNetCore 自动生成)向我的 Auth0 租户进行身份验证。
我收到以下错误:
Auth ErrorError,错误:access_denied,描述:不允许非全局客户端访问 APIv1
这是一个屏幕截图:
开放 API 规范如下所示:
"securitySchemes": {
"auth0": {
"type": "oauth2",
"flows": {
"clientCredentials": {
"tokenUrl": "https://example.auth0.com/oauth/token"
},
"authorizationCode": {
"authorizationUrl": "https://example.auth0.com/authorize?audience=test",
"tokenUrl": "https://example.auth0.com/oauth/token",
"scopes": { }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
audience我怀疑这与未指定有关。我在授权代码流方面遇到了类似的问题,但设法通过将受众作为查询字符串参数附加到authorizationUrl(如上所示)来实现此工作。不幸的是,同样的技巧不适用于客户端凭证流(即尝试将受众附加到tokenUrl)。我需要支持客户端凭证流,因为一条或多条路由需要仅锁定到 M2M 令牌。
有趣的是,如果我使用全局客户端 ID/秘密(在租户的高级设置下找到),它就可以工作,但我不确定我们是否应该使用它......
其他人也遇到过这个问题,如果是的话,找到解决方案是否运气好?
我正在将教程中的 auth0 集成到我自己的应用程序中,并且遇到了 auth0 日志中反映的一些身份验证问题。
点击我的反应登录按钮时会发生这种情况:
import React from "react";
import { useAuth0 } from "@auth0/auth0-react";
import '../components/App.css'
const LoginButton = () => {
const { loginWithRedirect } = useAuth0();
return <button class="btn btn-primary" onClick={() => loginWithRedirect()}>Log In</button>;
};
export default LoginButton;
Run Code Online (Sandbox Code Playgroud)
但是,在 Auth0 应用程序日志中,我看到我已成功通过身份验证,并且还获得Failed Exchange了Successful Login和Warning During Login。
Warning During Login这是日志的文本Warning During Login:
您正在使用 Auth0 开发密钥,该密钥仅用于开发和测试。应使用您自己的开发密钥配置此连接 (google-oauth2),以使同意页面能够显示您的徽标而不是 Auth0,并为此连接启用 SSO。不建议在生产环境中使用 AUTH0 开发密钥。要了解有关开发密钥的更多信息,请参阅 https://auth0.com/docs/connections/social/devkeys。
按照Auth0 网站上的说明已修复此问题。本质上: …
auth0 ×10
jwt ×3
angular ×2
reactjs ×2
go ×1
middleware ×1
nestjs ×1
node.js ×1
openapi ×1
rspec ×1
ruby ×1
swagger-ui ×1
swashbuckle ×1