我研究 SPA 的 SSO 解决方案已经有一段时间了。有很多解决方案存在细微的差别,同时我还发现并不是每个人对 SSO 都有相同的理解,并且没有多少针对 SPA 的 SSO 既定模式。因此,我并不要求详细的设计/架构,只是尝试看看这个主题是否有任何常见的做法。
SSO 意味着什么?
SPA有什么区别?(与常规网络应用程序相反)
我研究了一些解决方案,甚至是像 SAML 这样的旧解决方案(只是想了解一下 SSO..)。我当前的候选者是OpenId Connect,但后来我意识到 SPA 的差异,如果我的理解是正确的话:与常规 Web 应用程序不同,SPA 通常没有(或者我们尝试没有)后端服务器。SPA 所拥有的只是一个提供静态页面以及脚本、样式表和图像的服务器。
现在问题来了:
OpenId Connect基于OAuth2 授权代码授予类型,这意味着:
我的问题:
对于上述第1点,我的理解正确吗?是不是不要让 SPA 像常规 Web 应用程序那样拥有后端代码?
对于上面的第 2 点,这听起来像是一个解决方案,但这与OAuth2 隐式授权类型有什么本质上的不同?
并且,还有其他我应该知道但尚未探索的解决方案(框架、协议等)吗?
single-sign-on oauth-2.0 single-page-application openid-connect auth0
我有点被困在这里了。我正在客户端使用 Angular 4 编写一个 Web 应用程序,在服务器端使用 Node/Express/Mongo 编写一个 REST API,并使用 Auth0 API 进行身份验证。
在服务器端,我提供静态文件和所有到 Angular 的路由,如下所示:
const distDir = __dirname + "/dist/";
app.use(express.static(distDir));
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
Run Code Online (Sandbox Code Playgroud)
如果没有为所有 Angular 应用程序提供服务的 app.get 方法,我会收到 404 错误(例如无法 GET /callback)。
问题是 sendFile 发送一个 html 文件,无论调用是什么。在我的应用程序中,第一个调用是针对 js 文件的,如“网络”选项卡 (auth0.min.js) 中所示。所以我得到这个错误:
ERROR SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at e.CPp0.t.json (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.project (main.0e8acae237e497f792ab.bundle.js:1)
at e._next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.T14+.e.next (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at XMLHttpRequest.s (vendor.b69a8a4fa217eba4fba0.bundle.js:1)
at e.invokeTask (polyfills.043084ca495430fc14f3.bundle.js:1) …Run Code Online (Sandbox Code Playgroud) 我一直在尝试在我们的网站上使用 Auth0 的实现来运行 Cypress。我已经尝试了 Auth0 社区已经提供的大量内容,但似乎没有任何效果。
问题是:当我访问 url 端点时,它会将我重定向到 Auth0 登录页面。在那里我可以添加我的用户名和密码来登录。当我手动执行此操作时,这不是问题,但当我使用 cy.get 或 cy.visit 执行此操作时,出现以下错误:
Refused to frame 'auth0tenant.auth0.com' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".
Run Code Online (Sandbox Code Playgroud)
我尝试将以下标头添加到我的请求中:
X-Frame-Options: deny
Content-Security-Policy: frame-ancestors 'none'
Run Code Online (Sandbox Code Playgroud)
这是行不通的。
关注 Auth0 为 Cypress 提供的这篇博客也不起作用。
我还在我的 Auth0 租户设置中将点击劫持设置为 ON。那也没有完成任务。
我还尝试按照在浏览器中设置的方式在本地存储中设置 cookie,但这也不起作用。基本上,我获取了 jwt 令牌,对其进行解码,并将受众和域的值添加到浏览器中的本地存储中。但由于我无法修复的 CSP 错误,浏览器本身无法加载。
该地区的任何帮助将不胜感激。谢谢你!
我想将所有现有用户从 AWS Cognito 池移至 Auth0。最好使用现有密码,或者如果必须更改密码,则使用即时迁移。我在网上看到了将 Okta/Stormpath 等用户迁移到 auth0 的用户指南,但没有看到任何有关 cognito 到 autho inegration 的内容。任何指针都会有帮助。
很可能我误解了有关该主题的某些内容或在实施过程中遗漏了某些内容
我浏览了 Auth0 的文档,通过端点而不是 SDK 使用 PKCE 创建授权代码流,我看到我们提出了如下挑战和验证程序(来自 auth0 文档):
// Dependency: Node.js crypto module
// https://nodejs.org/api/crypto.html#crypto_crypto
function base64URLEncode(str) {
return str.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
}
var verifier = base64URLEncode(crypto.randomBytes(32));
Run Code Online (Sandbox Code Playgroud)
和
// Dependency: Node.js crypto module
// https://nodejs.org/api/crypto.html#crypto_crypto
function sha256(buffer) {
return crypto.createHash('sha256').update(buffer).digest();
}
var challenge = base64URLEncode(sha256(verifier));
Run Code Online (Sandbox Code Playgroud)
然后我们将质询传递给授权端点,如下所示(来自 auth0 文档):
https://YOUR_DOMAIN/authorize?
response_type=code&
code_challenge=CODE_CHALLENGE&
code_challenge_method=S256&
client_id=YOUR_CLIENT_ID&
redirect_uri=YOUR_CALLBACK_URL&
scope=SCOPE&
audience=API_AUDIENCE&
state=STATE
Run Code Online (Sandbox Code Playgroud)
并将代码和验证器传递到令牌端点,如下所示(再次来自 auth0 文档):
curl --request POST \
--url 'https://YOUR_DOMAIN/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data grant_type=authorization_code \ …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Angular 应用程序中使用Auth0,但是当我在 [https://manage.auth0.com/dashboard/] 中设置配置时,单击“保存更改”按钮时出现此错误
错误!有效负载验证错误:“对象未通过属性itiate_login_uri 上绝对-https-uri-or-empty 格式的验证:https://localhost:4200/en/signin”(启动登录 uri,必须是 https)。
如何解决这个错误?
我正在尝试为我的 UI 编写 E2E 测试。为了登录,我使用 auth0 和社交登录 - Github。我尝试了几种方法来获取 Github 的访问令牌:
使用 cypress 按钮点击:
cy.visit("https://myapp.io/login");
cy.get('.auth0-lock-social-button-text').click();
// Redirect me into Github login page.
cy.get('#login_field').type(my_username);
cy.get('#password').type(my_password);
cy.get('.btn').click();
Run Code Online (Sandbox Code Playgroud)
输出:网址:https: //github.com/session
页面内容:必须启用 Cookie 才能使用 GitHub。
有人有解释如何做的例子吗?
注意:我不想使用,cypress-social-logins因为我需要它来通过 CI。
谢谢。
看来使用Auth0,在M2M流程中,我们需要audience在授权请求中传递参数,并且将为此颁发令牌audience
curl --request POST \
--url https://domain.eu.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"xxxxx","client_secret":"xxxxx","audience":"my-api-audience","grant_type":"client_credentials"}'
Run Code Online (Sandbox Code Playgroud)
否则,会抛出错误
403 Forbidden: "{"error":"access_denied","error_description":"No audience parameter was provided, and no default audience has been configured"}"
Run Code Online (Sandbox Code Playgroud)
Client Credentials我尝试使用新的 Spring Security 5 方法和使用 WebClient 的 webflux 来通过 Spring Boot实现流程。
Spring 没有提供向 Auth 请求添加自定义参数的方法,正如这篇文章所示
https://github.com/spring-projects/spring-security/issues/6569
我必须实现一个自定义转换器。
一切似乎在启动时都注入得很好,但在访问客户端端点时从未调用转换后的内容,localhost/api/explicit因此我一直遇到这个audience问题。
@Configuration
public class WebClientConfig {
@Value("${resource-uri}")
String resourceUri;
@Value("${wallet-audience}")
String audience;
@Bean
WebClient webClient(OAuth2AuthorizedClientManager authorizedClientManager) {
var oauth2 = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
return …Run Code Online (Sandbox Code Playgroud) 所以我最近获得了使用 netlify 域的登录按钮,现在当我尝试单击注销按钮时,我被重定向到 localhost:3000 但我希望将其重定向回带有登录按钮的页面,是否有怎么办?以下是我的 URI 详细信息:
允许的回调 URL:
http://localhost:3000,https://auth0-sample-authentication.netlify.app
Run Code Online (Sandbox Code Playgroud)
允许的注销 URL
http://localhost:3000,https://auth0-sample-authentication.netlify.app
Run Code Online (Sandbox Code Playgroud)
允许的 Web 来源
http://localhost:3000,https://auth0-sample-authentication.netlify.app
Run Code Online (Sandbox Code Playgroud)
请告诉我是否需要包含更多代码
谢谢,
324hz win21H2 他/他
我正在尝试使用 Vitest 测试 Vue 组件,但为了做到这一点,我需要模拟 auth0
下面是我的 Navbar.test.ts 文件,但是当我运行测试时,我不断收到以下错误,Cannot read properties of undefined (reading 'mockReturnValue'似乎useAuth0未定义,即使我将其导入到页面顶部。也许我只是不太理解它的嘲笑的一面,但任何帮助将不胜感激。
import { vi } from 'vitest'
import { ref } from "vue";
import { shallowMount } from '@vue/test-utils'
import { useAuth0 } from '@auth0/auth0-vue';
import NavBar from "@/components/NavBar.vue";
const user = {
email: "user@test.com",
email_verified: true,
sub: ""
};
vi.mock("@auth0/auth0-vue");
const mockedUseAuth0 = vi.mocked(useAuth0, true);
describe("NavBar.vue", () => {
beforeEach(() => {
mockedUseAuth0.mockReturnValue({
isAuthenticated: ref(true),
user: ref(user),
logout: vi.fn(),
loginWithRedirect: vi.fn(), …Run Code Online (Sandbox Code Playgroud) auth0 ×10
oauth-2.0 ×3
angular ×2
cypress ×2
javascript ×2
auth0-lock ×1
e2e-testing ×1
express ×1
java ×1
migration ×1
node.js ×1
oauth ×1
openid ×1
pkce ×1
reactjs ×1
sendfile ×1
spring-boot ×1
unit-testing ×1
vitest ×1
vue.js ×1