本文整理汇总了C#中IdentityModel.Client.TokenClient.RequestResourceOwnerPasswordAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TokenClient.RequestResourceOwnerPasswordAsync方法的具体用法?C# TokenClient.RequestResourceOwnerPasswordAsync怎么用?C# TokenClient.RequestResourceOwnerPasswordAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IdentityModel.Client.TokenClient
的用法示例。
在下文中一共展示了TokenClient.RequestResourceOwnerPasswordAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Valid_User_IdentityScopes
public async Task Valid_User_IdentityScopes()
{
var client = new TokenClient(
TokenEndpoint,
"roclient",
"secret",
innerHttpMessageHandler: _handler);
var response = await client.RequestResourceOwnerPasswordAsync("bob", "bob", "openid email api1");
response.IsError.Should().Be(false);
response.ExpiresIn.Should().Be(3600);
response.TokenType.Should().Be("Bearer");
response.IdentityToken.Should().BeNull();
response.RefreshToken.Should().BeNull();
var payload = GetPayload(response);
payload.Count().Should().Be(10);
payload.Should().Contain("iss", "https://idsrv3");
payload.Should().Contain("aud", "https://idsrv3/resources");
payload.Should().Contain("client_id", "roclient");
payload.Should().Contain("sub", "88421113");
payload.Should().Contain("idp", "idsrv");
var amr = payload["amr"] as JArray;
amr.Count().Should().Be(1);
amr.First().ToString().Should().Be("password");
var scopes = payload["scope"] as JArray;
scopes.Count().Should().Be(3);
scopes.First().ToString().Should().Be("api1");
scopes.Skip(1).First().ToString().Should().Be("email");
scopes.Skip(2).First().ToString().Should().Be("openid");
}
示例2: GetToken
static TokenResponse GetToken(string tokenUrl, string clientId, string secret, string scope, string username = null, string password = null)
{
var client = new TokenClient(tokenUrl, clientId, secret);
if (string.IsNullOrWhiteSpace(username)||string.IsNullOrWhiteSpace(password))
return client.RequestClientCredentialsAsync(scope).Result;
else
return client.RequestResourceOwnerPasswordAsync(username, password, scope).Result;
}
示例3: GetClientToken
public static TokenResponse GetClientToken()
{
var client = new TokenClient("https://localhost:44333/connect/token", "carbon",
"21B5F798-BE55-42BC-8AA8-0025B903DC3B");
//return client.RequestClientCredentialsAsync("LeagueComparer").Result;
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "LeagueComparer").Result;
}
示例4: RequestToken
static TokenResponse RequestToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"roclient.reference",
"secret");
return client.RequestResourceOwnerPasswordAsync("bob", "bob", "api1").Result;
}
示例5: GetToken
static TokenResponse GetToken()
{
var client = new TokenClient(
"http://localhost:44333/connect/token",
"ConsoleApplication",
"F621F470-9731-4A25-80EF-67A6F7C5F4B8");
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "WebApi1").Result;
}
示例6: GetUserToken
/// <summary>
/// Request an access token on behalf of a user
/// </summary>
static TokenResponse GetUserToken()
{
var client = new TokenClient("https://localhost:44333/connect/token",
"freightshare2",
"IIPiBTywUcK5Qv0kvmVXbSiax5wBStDMGTAIA0T/RSM=");
//return client.RequestResourceOwnerPasswordAsync("bob", "secret", "api1").Result;
return client.RequestResourceOwnerPasswordAsync("alice", "secret", "api1").Result;
}
示例7: GetUserToken
static TokenResponse GetUserToken()
{
var client = new TokenClient(
"https://localhost:44333/connect/token",
"carbon",
"21B5F798-BE55-42BC-8AA8-0025B903DC3B");
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "api1").Result;
}
示例8: RequestToken
static TokenResponse RequestToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"roclient",
"secret");
//return client.RequestResourceOwnerPasswordAsync("wooboo","kop","read write").Result;
return client.RequestResourceOwnerPasswordAsync("bubu","bubu","read write").Result;
}
示例9: Authenticate
public async Task<IHttpActionResult> Authenticate(AuthenticateRequest authenticateRequest)
{
var tokenClient = new TokenClient("https://localhost:44302/connect/token", "AngularClient", "secret");
var result = await tokenClient.RequestResourceOwnerPasswordAsync(authenticateRequest.Username,authenticateRequest.Password, "Api"); //offline_access scope enables refresh token
return Ok(new
{
result.AccessToken,
result.RefreshToken
});
}
示例10: Login
public Task<TokenResponse> Login([FromBody]CredentialsModel credentials)
{
var clientId = (string)ConfigurationManager.AppSettings["oauth2.clientid"];
var client = new TokenClient(
(string)ConfigurationManager.AppSettings["openid.endpoints.token"],
clientId,
(string)ConfigurationManager.AppSettings["oauth2.client-secret"]
);
return client.RequestResourceOwnerPasswordAsync(credentials.Username, credentials.Password, clientId);
}
示例11: GetJwt
static string GetJwt()
{
var oauth2Client = new TokenClient(
Constants.TokenEndpoint,
"ro.client",
"secret");
var tokenResponse =
oauth2Client.RequestResourceOwnerPasswordAsync("bob", "bob", "write").Result;
return tokenResponse.AccessToken;
}
示例12: RequestToken
static TokenResponse RequestToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"roclient",
"secret");
// idsrv supports additional non-standard parameters
// that get passed through to the user service
var optional = new
{
acr_values = "tenant:custom_account_store1 foo bar quux"
};
return client.RequestResourceOwnerPasswordAsync("dabs", "dabs", "read write", optional).Result;
}
示例13: Main
private static void Main(string[] args)
{
var tokenClient = new TokenClient(Constants.TokenEndpoint, "roclient", "secret");
var response = tokenClient.RequestResourceOwnerPasswordAsync("bob", "bob", "read write offline_access").Result;
var refresh_token = response.RefreshToken;
while (true)
{
response = RefreshToken(refresh_token, tokenClient);
Console.ReadLine();
//CallService(response.AccessToken);
if (response.RefreshToken != refresh_token)
{
refresh_token = response.RefreshToken;
}
}
}
示例14: No_Identity_Scope
public async Task No_Identity_Scope()
{
var tokenClient = new TokenClient(
TokenEndpoint,
"roclient",
"secret",
innerHttpMessageHandler: _handler);
var response = await tokenClient.RequestResourceOwnerPasswordAsync("bob", "bob", "api1");
response.IsError.Should().BeFalse();
var userInfoclient = new UserInfoClient(
new Uri(UserInfoEndpoint),
response.AccessToken,
_handler);
var userInfo = await userInfoclient.GetAsync();
userInfo.IsError.Should().BeTrue();
userInfo.HttpErrorStatusCode.Should().Be(HttpStatusCode.Forbidden);
}
示例15: RequestTokenAsync
public virtual async Task<IResponse> RequestTokenAsync(string userName, string password) {
var disco = await DiscoveryClient.GetAsync(_options.Authority);
string clientId = _httpContext.Request.Headers[ClientId];
if (string.IsNullOrWhiteSpace(clientId)) {
clientId = _options.DefaultClientId;
}
string clientSecret = _httpContext.Request.Headers[ClientSecret];
if (string.IsNullOrWhiteSpace(clientSecret)) {
clientSecret = _options.DefaultClientSecret;
}
string scope = _httpContext.Request.Headers[Scope];
if (string.IsNullOrWhiteSpace(scope)) {
scope = _options.DefaultScope;
}
var client = new TokenClient(disco.TokenEndpoint, clientId, clientSecret);
var response = await client.RequestResourceOwnerPasswordAsync(userName, password, scope);
return ApiResponse.FromTokenResponse(response);
}