gpt4 book ai didi

thinktecture-ident-server - 无法使用 Postman 的 IdentityManager API

转载 作者:行者123 更新时间:2023-12-04 04:35:04 24 4
gpt4 key购买 nike

我正在使用 postman ,并且正在尝试从身份管理器中获取用户列表。但我无法正确配置应用程序。我尝试从 https://localhost/idm/api/users 获取用户

我获得了具有 API+idmgr+openid 范围的 token ,并且在我的声明中具有管理员角色。

这是启动文件:

namespace WebHost
{
internal class Startup
{
public void Configuration(IAppBuilder app)
{
LogProvider.SetCurrentLogProvider(new NLogLogProvider());

string connectionString = ConfigurationManager.AppSettings["MembershipRebootConnection"];

JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
Authority = "https://localhost/ids",
ClientId = "postman",
RedirectUri = "https://localhost",
ResponseType = "id_token",
UseTokenLifetime = false,
Scope = "openid idmgr",
SignInAsAuthenticationType = "Jwt",
Notifications = new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = n =>
{
n.AuthenticationTicket.Identity.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));
return Task.FromResult(0);
}
}
});

X509Certificate2 cert = Certificate.Get();

app.Map("/idm", adminApp =>
{
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
AllowedAudiences = new string[] { "https://localhost/ids" + "/resources" },
AuthenticationType = "Jwt",
IssuerSecurityTokenProviders = new[] {
new X509CertificateSecurityTokenProvider("https://localhost/ids", cert)
},
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active
});

var factory = new IdentityManagerServiceFactory();
factory.Configure(connectionString);

var securityConfig = new ExternalBearerTokenConfiguration
{
Audience = "https://localhost/ids" + "/resources",
BearerAuthenticationType = "Jwt",
Issuer = "https://localhost/ids",
SigningCert = cert,
Scope = "openid idmgr",
RequireSsl = true,
};

adminApp.UseIdentityManager(new IdentityManagerOptions()
{
Factory = factory,
SecurityConfiguration = securityConfig
});
});

app.Map(ConfigurationManager.AppSettings["IdentityServerSuffix"], core =>
{
IdentityServerServiceFactory idSvrFactory = Factory.Configure();
idSvrFactory.ConfigureCustomUserService(connectionString);

var options = new IdentityServerOptions
{
SiteName = "Login",

SigningCertificate = Certificate.Get(),
Factory = idSvrFactory,
EnableWelcomePage = true,
RequireSsl = true
};

core.UseIdentityServer(options);
});
}
}
}

我错过了什么?

最佳答案

对于那些可能想知道我是如何做到的人,我对 Owin 的东西以及 Identity Server 的工作原理进行了很多搜索,发现我的问题并没有那么远。

我删除了 JwtSecurityTokenHandler.InboundClaimTypeMap
我删除了 UseOpenId 的东西(如果您使用的是 openId 外部登录提供程序,请不要删除它(如果您使用的是 google、facebook 或 twitter,有相应的类,只需安装 nuget,它非常简单)

本栏目让你配置 不记名 token 这是我在我的应用程序中使用的默认类型 token (我决定使用 密码身份验证 来简化 Postman 请求进行自动测试,但我仍然使用 代码身份验证 在我的应用程序中)

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = ConfigurationManager.AppSettings["AuthorityUrl"],
ValidationMode = ValidationMode.ValidationEndpoint,
RequiredScopes = new[] { ConfigurationManager.AppSettings["ApiScope"] }
});

我已禁用 IdentityManagerUi 接口(interface),因为我计划使用 API
 app.Map(ConfigurationManager.AppSettings["IdentityManagerSuffix"].ToString(), idmm =>
{
var factory = new IdentityManagerServiceFactory();
factory.Configure(connectionString);

idmm.UseIdentityManager(new IdentityManagerOptions()
{
DisableUserInterface = true,
Factory = factory,
SecurityConfiguration = new HostSecurityConfiguration()
{
HostAuthenticationType = Constants.BearerAuthenticationType
}
});
});

我像这样配置身份服务器:
app.Map(ConfigurationManager.AppSettings["IdentityServerSuffix"], core =>
{
IdentityServerServiceFactory idSvrFactory = Factory.Configure();
idSvrFactory.ConfigureCustomUserService(connectionString);

var options = new IdentityServerOptions
{
SiteName = ConfigurationManager.AppSettings["SiteName"],

SigningCertificate = Certificate.Get(),
Factory = idSvrFactory,
EnableWelcomePage = true,
RequireSsl = true,
};

core.UseIdentityServer(options);
});

在 IdentityServerServiceFactory 中,我将这段代码称为:
var clientStore = new InMemoryClientStore(Clients.Get());

客户端的代码应该是这样的:
public static Client Get()
{
return new Client
{
ClientName = "PostMan Application",
ClientId = "postman",
ClientSecrets = new List<Secret> {
new Secret("ClientSecret".Sha256())
},
Claims = new List<Claim>
{
new Claim("name", "Identity Manager API"),
new Claim("role", IdentityManager.Constants.AdminRoleName),
},
**Flow = Flows.ResourceOwner**, //Password authentication
PrefixClientClaims = false,
AccessTokenType = AccessTokenType.Jwt,
ClientUri = "https://www.getpostman.com/",
RedirectUris = new List<string>
{
"https://www.getpostman.com/oauth2/callback",
//aproulx - 2015-11-24 -ADDED This line, url has changed on the postman side
"https://app.getpostman.com/oauth2/callback"
},

//IdentityProviderRestrictions = new List<string>(){Constants.PrimaryAuthenticationType},
AllowedScopes = new List<string>()
{
"postman",
"IdentityManager",
ConfigurationManager.AppSettings["ApiScope"],
Constants.StandardScopes.OpenId,
IdentityManager.Constants.IdMgrScope,
}
};
}

在 postman 方面,只需执行以下操作:
POST /ids/connect/token HTTP/1.1
Host: local-login.net
Cache-Control: no-cache
Postman-Token: 33e98423-701f-c615-8b7a-66814968ba1a
Content-Type: application/x-www-form-urlencoded

client_id=postman&client_secret=SecretPassword&grant_type=password&scope=APISTUFF&username=apiViewer&password=ICanUseTheApi

希望它会帮助某人

关于thinktecture-ident-server - 无法使用 Postman 的 IdentityManager API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34345963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com