kubectl当我使用带有标志的命令--token并指定令牌时,它仍然使用文件中的管理员凭据kubeconfig。
这就是我所做的:
NAMESPACE="default"
SERVICE_ACCOUNT_NAME="sa1"
kubectl create sa $SERVICE_ACCOUNT_NAME
kubectl create clusterrolebinding list-pod-clusterrolebinding \
--clusterrole=list-pod-clusterrole \
--serviceaccount="$NAMESPACE":"$SERVICE_ACCOUNT_NAME"
kubectl create clusterrole list-pod-clusterrole \
--verb=list \
--resource=pods
TOKEN=`kubectl get secrets $(kubectl get sa $SERVICE_ACCOUNT_NAME -o json | jq -r '.secrets[].name') -o json | jq -r '.data.token' | base64 -d`
# Expected it will fail but it doesn't because it uses the admin credentials
kubectl get secrets --token $TOKEN
Run Code Online (Sandbox Code Playgroud)
该令牌有权列出 pod,因此我预计kubectl get secrets --token $TOKEN会失败,但事实并非如此,因为它仍然使用管理员的上下文。
我不创建新的上下文,我知道kubectl …
我正在尝试使用 Postman 触发经过身份验证的 GCP 云功能。
为此,我创建了一个具有“Cloud Functions Invoker”角色的专用服务帐户,并下载了一个结构如下的 .json 密钥:
{
"type": "service_account",
"project_id": "xxx",
"private_key_id": "xxx",
"private_key": "-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n",
"client_email": "xxx.iam.gserviceaccount.com",
"client_id": "xxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "xxx.iam.gserviceaccount.com"
}
Run Code Online (Sandbox Code Playgroud)
我尝试将整个“private_key”(-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n)粘贴为承载令牌,但我得到出现以下错误:
<title>401 Unauthorized</title>
Run Code Online (Sandbox Code Playgroud)
现在,如何使用 GCP 中的 .json 文件通过 Postman 进行身份验证?我应该使用哪些参数?
google-cloud-platform postman bearer-token google-cloud-functions
今天我正在检查是否可以将我的应用程序迁移到 .NET 8。起初一切正常,当我尝试登录时,我在控制台中收到以下错误:
无法验证令牌。
Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException:IDX10506:签名验证失败。在 TokenValidationParameters 上指定的用户定义的“委托”未返回“Microsoft.IdentityModel.JsonWebTokens.JsonWebToken”,但在验证令牌时返回“System.IdentityModel.Tokens.Jwt.JwtSecurityToken”
我的客户正在使用 PingID 的定制实现。使用内省来验证令牌,这就是我编写自定义令牌验证器的原因:
public class PingTokenValidator : ISecurityTokenValidator
{
private readonly IConfiguration configuration;
private readonly ILogger log;
private readonly OpenIdConnectConfiguration openIdConnectConfiguration;
private readonly JwtSecurityTokenHandler tokenHandler;
public PingTokenValidator(OpenIdConnectConfiguration openIdConnectConfiguration,
IConfiguration configuration)
{
this.tokenHandler = new();
this.openIdConnectConfiguration = openIdConnectConfiguration;
this.configuration = configuration;
this.log = Log.ForContext<PingTokenValidator>();
}
public bool CanReadToken(string securityToken)
{
return true;
}
public ClaimsPrincipal ValidateToken(string securityToken,
TokenValidationParameters validationParameters,
out SecurityToken validatedToken)
{
try
{
var principal = this.tokenHandler.ValidateToken(securityToken, validationParameters, out validatedToken);
if (tokenExistInCache …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 access_token 执行 POST 请求,并且使用 POSTMAN 可以正常工作,但是当我尝试在 Delphi 上执行相同的请求时,我找不到添加“Authorization=Bearer eyxxxxxx ... " 到请求标头,就像 POSTMAN 一样。
邮递员请求(运行良好):
POST /somepath HTTP/1.1
Host: someurl.com.br
Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.....
Content-Type: application/json
(省略正文内容)
Delphi 生成的 Indy 请求,被 HTTP Analyzer 捕获(总是返回 401 Forbidden 错误,因为没有“Authorization=Bearer”部分):
POST /somepath HTTP/1.1
主机:someurl.com.br
内容类型:application/json
(省略正文内容)
我尝试使用下面的代码添加标头,但在请求时未生成带有“Authorization=Bearer eyxxxxxx...”的标头部分,返回 401 Forbidden 错误。
FIdHTTP.Request.CustomHeaders.FoldLines := False;
FIdHTTP.Request.CustomHeaders.Add('Authorization=Bearer ' + txtToken.Text);
Run Code Online (Sandbox Code Playgroud) 我想在他们成功登录后返回用户名以显示在我的网络应用程序的右上角。我想将它与承载令牌返回的 json 一起发送。为了生成令牌身份验证,我使用了 ASP.NET Web API 和 Owin middlehawe。
{
"access_token": "blah",
"token_type": "bearer",
"expires_in": 599
}
Run Code Online (Sandbox Code Playgroud)
我希望回报是这样的
{
"access_token": "blah",
"token_type": "bearer",
"expires_in": 599,
"displayusername":"Hi Mundo"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过索赔,但那些并没有给出我想要的结果。
我曾尝试使用 AuthenticationProperties 但不起作用
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
if (validation works)
{
// add claims
var moreInfo = new AuthenticationProperties(new Dictionary<string, string> { { "username", "Don"}, { "Department","MIS"} });
var ticket = new AuthenticationTicket(identity, moreInfo);
context.Validated(ticket);
}
else
{
context.SetError("invalid_grant", "The user name or …Run Code Online (Sandbox Code Playgroud) 我正在寻找有关配置owin中间件承载令牌身份验证以支持Open Id Connect密钥轮换的指南。
在运行结束编号连接规范说,关于密钥轮换如下:
签名密钥的旋转可以通过以下方法完成。签名者将其密钥发布到位于其jwks_uri位置的JWK集中,并将签名密钥的孩子包含在每个消息的JOSE标头中,以向验证者指示要使用哪个密钥来验证签名。可以通过在jwks_uri位置将新密钥定期添加到JWK集中来滚动密钥。签名者可以根据自己的判断开始使用新密钥,并使用kid值将更改发送给验证者。验证者知道看到不熟悉的孩子值时,会知道返回jwks_uri位置以重新获取密钥。
我可以在此主题上找到最相似的问题是: OWIN OpenID Connect中间件中的SecurityTokenSignatureKeyNotFoundException连接到Google
该解决方案不太有效,因为在颁发新私钥到客户端刷新其公钥缓存之间,您会遇到错误。
因此,我希望将客户端配置为在找到有效,正确签名,未过期且其子代不在本地缓存的JWT令牌时下载丢失的公共JWK密钥。
我当前使用的是IdentityServer3.AccessTokenValidation,但是当客户端与无法识别的孩子一起使用令牌时,客户端不会下载新密钥。
我快速浏览了Microsoft.Owin.Security.Jwt-> UseJwtBearerAuthentication以及Microsoft.Owin.Security.OpenIdConnect-> UseOpenIdConnectAuthentication,但我没有走太远。
我正在寻找扩展/配置上述任何软件包以支持按键旋转的方向。
我有两个应用程序,一个是Web应用程序(Web-UI),另一个是Web API。首先,我在Web-UI中实现了Azure AD身份验证。这两个应用程序均已在Azure中注册并相互推动。-
首先我的配置
tenant: '99c7da52-56fc-49ca-aa95-111111111111',
clientId: '6b0a79eb-0e0d-4a00-9652-111111111111
Run Code Online (Sandbox Code Playgroud)
登录就像一个迷住我成功获得令牌。在此情况下,其外观如下所示:
Header
{
"typ": "JWT",
"nonce": "AQABAAAAAABHh4kmS_aKT5XrjzxRAtHzn-GbcsmT8MupNislUn7vudKeuWR-HgBEd2ceWxQ7UulHr-uachkZA9cWVIj5ah3yzI68oYKyzc-QdynAf3a5DSAA",
"alg": "RS256",
"x5t": "z44wMdHu8wKsumrbfaK98qxs5YI",
"kid": "z44wMdHu8wKsumrbfaK98qxs5YI"
}
Payload
{
"aud": "00000003-0000-0000-c000-000000000000",
"iss": "https://sts.windows.net/99c7da52-56fc-49ca-aa95-8f7fb09c995e/",
"iat": 1517145610,
"nbf": 1517145610,
"exp": 1517149510,
"acr": "1",
"aio": "ATQAy/8GAAAAYOQzoNWpu5XcyTPibpz9lnb/bMGY3H4iTdEdz/zvWwrTt1mvvWiLToaNPYZwHsBD",
"amr": [
"pwd",
"mfa"
],
"app_displayname": "My Project",
"appid": "6b0a79eb-0e0d-4a00-9652-3098cc95804f",
"appidacr": "0",
"e_exp": 262800,
"family_name": "XXXXXXXXX",
"given_name": "XXXXXXXXXX",
"ipaddr": "93.245.65.135",
"name": "Myname, Firstname",
"oid": "1a4d0d0f-8137-4c1d-aa34-2cccf10f8206",
"platf": "3",
"puid": "100300008AAF747A",
"scp": "Directory.Read.All email Group.Read.All profile User.Read User.Read.All User.ReadBasic.All",
"sub": "IBv63_IIq4zpkv_UlVwaxmAm0RP3d17xq4hKil4HRD0",
"tid": "89c7da52-56fc-49ca-aa95-8f7fb09c995e",
"unique_name": …Run Code Online (Sandbox Code Playgroud) asp.net jwt azure-active-directory bearer-token asp.net-core-mvc-2.0
我正在尝试使用 Postman 测试几个端点。
所有端点,都需要一个可以通过登录获得的令牌。
所以我这样做了:
请求 #1
登录成功后,我可以从响应中访问令牌,然后将该令牌存储在我的全局变量中。
let token = pm.response.json().location
console.log('Token : ', token.split("?token=")[1]);
pm.globals.set("token", token)
Run Code Online (Sandbox Code Playgroud)
我需要使用该令牌作为我的请求 #2 的授权类型承载令牌。
我可以将其复制并粘贴到令牌框中,但我尽量避免手动执行此操作,有没有办法自动执行此操作,以便我可以按顺序运行这 2 个请求?
我见过与此问题类似的线程,但我没有运气解决它。登录工作成功,但是当我尝试在主页中获取登录用户的数据时,我收到此错误 401 未经授权,邮递员中也显示相同的错误
我的启动.cs
public class Startup
{
private string _connectionString=null;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//Inject AppSettings
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
_connectionString = Configuration["secretConnectionstring"];
//without this it will define for example id to Id
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(options => {
var resolver = options.SerializerSettings.ContractResolver;
if (resolver != null)
(resolver as DefaultContractResolver).NamingStrategy = …Run Code Online (Sandbox Code Playgroud) 我一直在努力使多个身份验证方案在 Asp.net 核心 2.1 中正常工作。
我使用带有隐式流和 OpenIdConnect 作为协议的 Identity Server。
当仅使用其中一种方案(例如 Cookie 或 Bearer)授权操作或控制器时,该功能可以正常工作。
例子:
[Authorize(AuthenticationSchemes = "Cookies")]
[Route("Cookies")]
public class BearerAndCookiesController : Controller {
Run Code Online (Sandbox Code Playgroud)
但是,如果我在 Authorize 属性上指定了两种方案,那么它会部分失败。Bearer 正常工作,但是当我尝试在浏览器中查看页面时,它尝试重定向到本地登录页面 ( http://localhost/Account/Login )。
当我检查 Identity Server 的调试日志时,没有返回任何内容,这是有道理的,因为它没有尝试联系管理局。但是,当我查看测试 MVC 站点的调试日志时,Bearer 和 Cookie 方案都受到挑战:
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5002/cookies
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Route matched with {action = "Get", controller = "BearerAndCookies"}. Executing action MvcClient.Controllers.BearerAndCookiesController.Get (MvcClient)
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService:Information: Authorization failed.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
Microsoft.AspNetCore.Mvc.ChallengeResult:Information: Executing ChallengeResult with authentication schemes (Bearer, …Run Code Online (Sandbox Code Playgroud) cookies authorization bearer-token asp.net-core identityserver4
bearer-token ×10
jwt ×3
asp.net ×2
asp.net-core ×2
c# ×2
postman ×2
.net-8.0 ×1
access-token ×1
angular7 ×1
asp.net-mvc ×1
cookies ×1
delphi ×1
express-jwt ×1
http ×1
indy ×1
json ×1
kubectl ×1
kubernetes ×1
owin ×1
security ×1