我正在尝试从 gradle 项目调用 webAPI。
我的 build.gradle 如下。
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile 'org.springframework.boot:spring-boot-starter-webflux'
compile 'org.projectreactor:reactor-spring:1.0.1.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)
如果我删除以下依赖项
compile 'org.springframework.boot:spring-boot-starter-webflux'
Run Code Online (Sandbox Code Playgroud)
它有效,但如果我将其添加回来。它给出了错误
Web server failed to start. Port 8080 was already in use.
Run Code Online (Sandbox Code Playgroud)
那么,我该如何解决这个问题,以便我可以使用 webclient?因为应用程序不是需要端口才能运行的 Web 应用程序。它是一种微服务。
我只想使用 Spring Boot 的 WebClient。如何在不将我的应用程序转换为 Web 应用程序的情况下使用它。
我创建了 Nest js 项目,如下所示。
nest new project-name
并从 nuxt3 导入以下内容,其类型为module
带有文件扩展名的 Node js mjs
(导入的类型定义不需要编写 mjs)。
import { ViteBuildContext, ViteOptions, bundle } from '@nuxt/vite-builder-edge';
它给了我以下错误。
Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs not supported. Instead change the require of c:\project\node_modules\@nuxt\vite-builder-edge\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.
所以我尝试添加"type": "module"
package.json 所以现在我收到以下错误。
Uncaught ReferenceError ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because …
我在以下代码中得到用户未定义。
我已经从 MVC 验证了用户。
但是当我使用 signinSilentCallback 获取该用户的详细信息时,它在 js 中使用 oidc-client 变得未定义。
它也没有给出任何错误。
var mgr = new UserManager({
authority: "http://localhost:5000",
client_id: "js",
redirect_uri: "http://localhost:50144/signin-oidc",
silent_redirect_uri: "http://localhost:50144/signin-oidc",
response_type: "id_token token",
post_logout_redirect_uri: "http://localhost:50144/signout-callback-oidc",
});
mgr.signinSilentCallback().then(function (user) {
//**Here user is undefined.**
axios.defaults.headers.common['Authorization'] = "Bearer " + user.access_token;
});
Run Code Online (Sandbox Code Playgroud)
在 Identityserver 4 中,客户端定义如下。
new Client
{
ClientId = "js",
ClientName = "js",
ClientUri = "http://localhost:50144",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RequireClientSecret = false,
AccessTokenType = AccessTokenType.Jwt,
RedirectUris =
{
"http://localhost:50144/signin-oidc",
},
PostLogoutRedirectUris = …
Run Code Online (Sandbox Code Playgroud) 在身份服务器身份验证后,当它重定向到我的应用程序时,它给出
异常:关联失败。地点未知
现在因为我正在使用SPA。这条路肯定是没有的。但问题是我如何定义它。我应该在那里做什么。
我使用了 Identityserver 的混合流。
https://localhost:44375/signin-oidc
我已经提到了以下内容。
但在上面的链接中有一个 SPA 中间件。这是VueCliMiddleWare。(对我来说,这正在造成问题。路线。)
(对于其余路由,它按照以下代码返回索引文件。只有此/oidc-client路径不起作用。)
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
})
.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new List<string> { "index.html" } });
Run Code Online (Sandbox Code Playgroud)
如果我定义以下
routes.MapSpaFallbackRoute(
name: "spa - fallback",
defaults: new { controller = "CatchAll", action = "Index" });
Run Code Online (Sandbox Code Playgroud)
然后该路由重定向到该控制器。但我无法返回索引文件。
我有以下 package.json
{
"dependencies": {
"@elastic/elasticsearch": "^7.16.0",
"@nestjs/common": "^8.2.4",
"@nestjs/config": "^1.1.5",
"@nestjs/core": "^8.2.4",
"@nestjs/jwt": "^8.0.0",
"@nestjs/microservices": "^8.2.4",
"@nestjs/passport": "^8.0.1",
"@nestjs/platform-express": "^8.2.4",
"@nestjs/testing": "^8.2.4",
"@nestjs/websockets": "^8.2.4",
"@nuxt/content": "^1.15.1",
"@nuxt/typescript": "^2.8.1",
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/pwa": "^3.3.5",
"@riophae/vue-treeselect": "0.4.0",
"@typegoose/typegoose": "^9.4.0",
"@types/fabric": "^4.5.6",
"@types/multer": "^1.4.7",
"acorn": "^8.6.0",
"adm-zip": "^0.5.9",
"ajv": "^8.8.2",
"amqplib": "^0.8.0",
"animejs": "^3.2.1",
"axios": "^0.24.0",
"bootstrap": "^5.1.3",
"connect-mongo": "^4.6.0",
"copyfiles": "^2.4.1",
"core-js": "^3.20.1",
"cross-env": "^7.0.3",
"element-theme-dark": "^1.0.3",
"element-ui": "^2.15.6",
"express": "^4.17.2",
"express-session": "^1.17.2",
"fabric": "^4.6.0",
"file-saver": "^2.0.5",
"glob": "^7.2.0",
"http-status-codes": "^2.1.4",
"jQuery-QueryBuilder": …
Run Code Online (Sandbox Code Playgroud) 我在我的客户端 startup.cs 中有以下内容。
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; // cookie middle setup above
options.Authority = AuthSetting["Authority"]; // Auth Server
options.RequireHttpsMetadata = false; // only for development
options.ClientId = AuthSetting["ClientId"]; // client setup in Auth Server
options.ClientSecret = AuthSetting["ClientSecret"];
options.ResponseType = "code id_token"; // means Hybrid flow (id + access token)
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
//options.ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
//options.ClaimActions.Clear(); ///sf/answers/3352732631/
//options.ClaimActions.MapUniqueJsonKey("Aes", "Aes");
//options.ClaimActions.MapUniqueJsonKey("foo", "foo");
//options.ClaimActions.MapJsonKey("Aes", "Aes"); //https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/issues/210 …
Run Code Online (Sandbox Code Playgroud) 我正在使用 axios 和 typescript。
我有一个简单的 axios 拦截器,编码如下。
// Add a response interceptor
axios.interceptors.response.use((response: AxiosResponse<any>) => {
// Do something with response data
return response;
}, (error: any) => {
// Do something with response error
// Here "error.response" is undefined.
return Promise.reject(error);
});
Run Code Online (Sandbox Code Playgroud)
我想做的是在未经身份验证时需要重定向到其他位置(identityserver SSO 页面,但我猜这与这里不相关)。
因此,当调用我的 API 时,如果未通过正确的位置进行身份验证,则会返回 302 状态代码。
但 axios 不会自动重定向到该位置。
如果我必须手动重定向,那仍然可以。
但我得到的“error.response”未定义。
那么现在我该如何重定向?因为由于“error.response”未定义,我无法检测到状态代码。
在网络选项卡中,它显示如下。
响应选项卡显示如下。没有可用的响应数据...!!!
我究竟做错了什么?
我有一个树结构。以文件夹为例。
如何使用 GraphQL 将嵌套查询查询到 N 级。
让我们举个例子,因为我在课堂上有以下属性。
public class DocumentField
{
public int Id { get; set; }
public string Name { get; set; }
public List<DocumentField> Children { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
服务器端的设计方式是,如果有孩子,那么它将作为孩子包括在内。但是 graphql 层正在限制它,因为我的查询如下。
以下查询不会带来孩子的结果。
query ($folderId: Int!) {
folder(folderId: $folderId) {
id,
name
}
}
Run Code Online (Sandbox Code Playgroud)
以下查询给出错误为:嵌套查询 DocumentFieldICollection 类型的字段子项必须有一个子选择
query ($folderId: Int!) {
folder(folderId: $folderId) {
id,
name,
children
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用带有混合流的身份服务器的 vue cli 中间件。在 Ajax 调用中,我已手动重定向到身份提供者,如下所示。
options.Events.OnRedirectToIdentityProvider = context =>
{
if (context.Request.Path.StartsWithSegments("/api"))
{
if (context.Response.StatusCode == (int)HttpStatusCode.OK)
{
context.ProtocolMessage.State = options.StateDataFormat.Protect(context.Properties);
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
context.Response.Headers["Location"] = context.ProtocolMessage.CreateAuthenticationRequestUrl();
}
context.HandleResponse();
}
return Task.CompletedTask;
};
Run Code Online (Sandbox Code Playgroud)
在从身份服务器回调时,我收到以下错误。
KeyNotFoundException:字典中不存在给定的键“OpenIdConnect.Code.RedirectUri”。
下面是调用堆栈。
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync() Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext 上下文) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext 上下文) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文)
怎么了?
我正在使用下面存储库中的身份服务器。
https://github.com/IdentityServer/IdentityServer4
我的分叉仓库(带有上面的代码)
c# asp.net-core-mvc asp.net-core identityserver4 asp.net-core-2.1
当我尝试使用以下命令重置弹性搜索密码时(在弹性搜索的 bin 目录中)。
elasticsearch-reset-password -u elastic -i
Run Code Online (Sandbox Code Playgroud)
它抛出以下错误。
warning: ignoring JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot\; using bundled JDK
02:00:13.407 [main] WARN org.elasticsearch.common.ssl.DiagnosticTrustManager - failed to establish trust with server at [172.29.208.1]; the server provided a certificate with subject name [CN=KRISHNA], fingerprint [ef47a4306ed5c7bdc8db75ab0386e7519e2c0d8b], no keyUsage and no extendedKeyUsage; the session uses cipher suite [TLS_AES_256_GCM_SHA384] and protocol [TLSv1.3]; the certificate has subject alternative names [IP:fe80:0:0:0:a4b3:95fe:147:c957,DNS:KRISHNA,IP:fe80:0:0:0:9cea:564f:faff:5474,IP:fe80:0:0:0:2842:9d64:6174:b4ab,IP:192.168.56.1,DNS:localhost,IP:192.168.74.1,IP:192.168.59.1,IP:fe80:0:0:0:bd4d:ac80:922d:4faf,IP:127.0.0.1,IP:0:0:0:0:0:0:0:1,IP:192.168.164.1,IP:192.168.1.2,IP:fe80:0:0:0:d859:bf5d:cd56:c037]; the certificate is issued by [CN=Elasticsearch security auto-configuration HTTP CA]; the certificate is signed by (subject [CN=Elasticsearch security auto-configuration …
Run Code Online (Sandbox Code Playgroud) authentication https change-password command-line-interface elasticsearch
asp.net-core ×2
c# ×2
node.js ×2
typescript ×2
.net-core ×1
ajax ×1
axios ×1
gradle ×1
graphql ×1
https ×1
java ×1
javascript ×1
mjs ×1
node-modules ×1
npm ×1
npm-install ×1
nuxtjs3 ×1
spring-boot ×1
vue-cli-3 ×1