authorization 相关问题

授权是确定是否允许用户,程序或设备以特定方式访问受保护资源的过程。授权是计算机安全实践的关键主题。

如何在Go中设置Authorization Beare token header?

我目前正在使用 JWT 令牌进行身份验证和授权过程。我希望在“Authorization: Bearer”中设置 jwt 令牌。 w.Header().Add("授权", "承载...

回答 1 投票 0

为什么应用程序的主功能代码在授权工作流之前开始运行?

我正在构建一个应用程序,可以帮助我将曲目从我的库移动到另一个播放列表,这需要我完成 Spotify 授权工作流程。我相当确定范围是正确的并且......

回答 1 投票 0

防伪代币最佳实践

我正在使用asp.net core Rest API。我在cookie中设置了JWT令牌,但存在CSRF威胁。我搜索了一下,发现防伪令牌应该存储为cookie。但我这里有个问题: 难道是……

回答 0 投票 0

在 .net 6 blazor 应用程序中进行身份验证后,如何将自定义声明添加到 ClaimsPrincipal?

https://learn.microsoft.com/en-us/aspnet/core/security/authorization/claims?source=recommendations&view=aspnetcore-7.0 上面的文章很好地解释了如何利用

回答 2 投票 0

ASP .NET 中的 RBAC

我正在使用asp .net idneitty和duende身份服务器,所以我的数据库ASPNETROLES和ApiScope(api1.read,api1.write,.....)中有2个表,我的问题是我想将这些范围分配给

回答 0 投票 0

ASP.NET Core 使用(Json Web Token)JWT 来验证会话

我正在尝试将 JWT 身份验证添加到我的 Razor Pages Web 应用程序中。我希望用户输入他的电子邮件地址,然后检查该电子邮件是否存在于我的数据库中。如果地址是存储...

回答 0 投票 0

如何拒绝访问没有 PreAuthorize 注释的控制器?

我这里有 Spring Boot Web 应用程序。 它已升级为以下设置: Java 17 春季引导 3.0.4 弹簧安全 6.0.2 码头 11 服务器 当我启动应用程序时,我得到这个 lin...

回答 1 投票 0


Web 和桌面客户端应用程序的单点登录

我的团队正在对遗留应用程序进行现代化改造。其中一部分是用新的网络客户端替换旧的桌面客户端。在可预见的未来,两个客户端将并行存在

回答 0 投票 0

我应该采取什么方法在 Lambda(触发器)中实施授权而不使用 AppSync 用于我的项目的特定模块?

我目前在我的项目中结合 AppSync 和 Cognito 使用 Amplify 进行身份验证。后端 API 处理与 DynamoDB 数据库的交互。然而,我现在面临一个极限......

回答 0 投票 0

AllowAnonymous 找不到

我正在按照本教程将 JWT 身份验证添加到我的 dotnet 核心 web api 中。我在我的控制器中添加了 [AllowAnonymous] 属性方法,但是我收到一个错误说明 t...

回答 1 投票 0

如何在使用带有 auth0 的 PKCE 实施授权代码流时将用户详细信息包含在访问令牌 JWT 负载中?

我正在尝试通过在个人 Web 应用程序中使用 PKCE 实现授权代码流,但我被卡住了,所以任何帮助将不胜感激。该网站的目标是让用户登录(w ...

回答 0 投票 0

Spring Boot:使用Spring Boot时只允许Postman“GET”请求,不允许“POST”、“PUT”或“DELETE”;他们会产生“401 Unauthorized”错误

我是 Spring Boot 的新手,现在,我正在根据本教程构建一个应用程序。我的代码如下所示。 代码片段 pom.xml 文件: 我是 Spring Boot 的新手,现在,我正在根据 本教程 构建应用程序。我的代码如下所示。 代码片段 pom.xml文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.6</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.pokemonreview</groupId> <artifactId>api</artifactId> <version>0.0.1-SNAPSHOT</version> <name>api</name> <description>Pokemon Review API Course 2022</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> <version>3.0.6</version> </dependency> <dependency> <groupId>com.rungroop</groupId> <artifactId>web</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> application.properties 文件(简单密码不是秘密,仅用于测试目的): spring.datasource.url=jdbc:postgresql://localhost:5432/pokemonApiCourse spring.datasource.username=postgres spring.datasource.password=postgres spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=update spring.security.user.name=test spring.security.user.password=test spring.jpa.show-sql=true 型号: package com.pokemonreview.api.models; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor @Entity public class PokemonEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private String type; } 控制器: package com.pokemonreview.api.controllers; import java.util.ArrayList; import java.util.List; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import com.pokemonreview.api.models.PokemonEntity; @RestController @RequestMapping("/api/") public class PokemonController { @GetMapping("pokemon") public ResponseEntity<List<PokemonEntity>> getPokemons() { List<PokemonEntity> pokemonEntities = new ArrayList<PokemonEntity>(); pokemonEntities.add(new PokemonEntity(1L, "Squirtle", "Water")); pokemonEntities.add(new PokemonEntity(2L, "Pikachu", "Electric")); pokemonEntities.add(new PokemonEntity(3L, "Charmander", "Fire")); return ResponseEntity.ok(pokemonEntities); } @GetMapping("pokemon/{id}") public PokemonEntity pokemonDetail(@PathVariable Long id) { return new PokemonEntity(id, "Squirtle", "Water"); } @PostMapping("pokemon/create") @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<PokemonEntity> createPokemon(@RequestBody PokemonEntity pokemonEntity) { System.out.println(pokemonEntity.getName()); System.out.println(pokemonEntity.getType()); return new ResponseEntity<PokemonEntity>(pokemonEntity, HttpStatus.CREATED); } @PutMapping("pokemon/{id}/update") public ResponseEntity<PokemonEntity> updatePokemon(@RequestBody PokemonEntity pokemonEntity, @PathVariable("id") Long id) { System.out.println(pokemonEntity.getName()); System.out.println(pokemonEntity.getType()); return ResponseEntity.ok(pokemonEntity); } @DeleteMapping("pokemon/{id}/delete") public ResponseEntity<String> deletePokemon(@PathVariable("id") Long id) { System.out.println(id); return ResponseEntity.ok("Pokemon deleted successfully"); } } 我所做的修改 请注意…… <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> <version>3.0.6</version> </dependency> … 是我添加到 pom.xml 文件中的,但它确实 not 是否存在有所不同。 总是需要身份验证——不管是否添加Spring Security依赖项! (这是为什么?在教程中,需要no授权!)——如果我不添加这两行…… spring.security.user.name=test spring.security.user.password=test …到application.properties文件,每次启动user应用程序时都会生成用户Spring Boot的密码。 此外,我的 id 变量不是 int,如教程中所示,而是 Long。 此外,请注意本教程中使用了javax.persistence包。唯一向我建议的包是jakarta.persistence包。 Postman问题:只允许GET请求 我正在使用 Postman 来测试 GET、POST、PUT 和 DELETE 请求,但只有 GET 请求有效。 每次,我的Authorization选项卡中的选项设置如下: Type:Basic Auth Username:test Password:test 工作GET请求 GET 上的第一个 http://localhost:8080/api/pokemon 请求产生以下结果: [ { "id": 1, "name": "Squirtle", "type": "Water" }, { "id": 2, "name": "Pikachu", "type": "Electric" }, { "id": 3, "name": "Charmander", "type": "Fire" } ] 在GET上第二次http://localhost:8080/api/pokemon/5请求的结果如下: { "id": 5, "name": "Squirtle", "type": "Water" } 失败POST、PUT和DELETE请求 POST 请求是在 http://localhost:8080/api/pokemon/create 上进行的,在 Body 选项卡中,选择了 raw 和 JSON 并插入以下内容: { "name": "Pidgey", "type": "Earth" } 如果我现在点击Send,什么都没有返回,状态401 Unauthorized显示。 PUT(http://localhost:8080/api/pokemon/5/update)和DELETE(http://localhost:8080/api/pokemon/5/delete)请求产生相同的结果。 怎么了?在教程中,一切正常,我已经尝试根据我在互联网上找到的解决方案以多种方式调整pom.xml和application.properties文件,但所有这些都没有解决我的问题。 我终于找到问题所在了。 Spring Security 没有正确配置。当我添加以下包和类时,一切都开始正常工作: package com.pokemonreview.api.security; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { httpSecurity.csrf() .disable() .authorizeHttpRequests() .requestMatchers("/api/pokemon/**") .permitAll(); return httpSecurity.build(); } }

回答 1 投票 0

注册验证采取什么方式? [关闭]

所以我在我的 nestJS 应用程序中通过电子邮件实施注册验证,一旦创建了帐户,就会向用户发送一封带有验证链接的验证邮件。 现在在这里

回答 0 投票 0

getFolderById 在应用程序编辑器中工作正常,但不会在相关电子表格中

我有一个旨在生成发票的电子表格。每张发票一张,以及一些用于管理内容的复选框。其中之一旨在将工作表作为 pdf 文件保存到 ...

回答 1 投票 0

第一次登录需要刷新

当我登录时,如果不刷新页面,我无法将授权信息传递给我的应用程序。 登录服务; loginService(auth: Auth): Observable { 返回 this.apollo ....

回答 1 投票 0

如何根据环境在 FastAPI 中禁用身份验证?

我有一个 FastAPI 应用程序,我通过注入依赖函数为其启用身份验证。 控制器.py 路由器 = APIRouter( 前缀="/v2/测试", 标签=["helloWorld"],

回答 1 投票 0

我需要更改哪些权限才能为 Google 群组生成令牌?

我正在尝试发出从 Google 群组获取消息的请求,但是用于从用户获取消息的令牌请求不适用于群组,这表明我有一些变化......

回答 0 投票 0

在 Thymeleaf 和 Spring 的标头中传递 JWT 令牌

我想将 JWT 令牌作为授权标头与我的请求一起传递,但我正在使用 Thymeleaf 和 Spring Security 在我的控制器可以在 HttpRes 中添加标头之前拦截请求...

回答 0 投票 0

httpContext.User 声明在通过 .NET 6 中的自定义身份验证处理程序后未更新

我正在使用.Net 6 WebApi。我需要支持双重身份验证方案。一种方案是使用标准 OIDC 提供的访问令牌,为此我使用标准的 AddJwtBearer 扩展方法...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.