当前位置: 首页>>代码示例>>C#>>正文


C# TokenClient.RequestResourceOwnerPasswordAsync方法代码示例

本文整理汇总了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");
        }
开发者ID:Rolosoft,项目名称:IdentityServer3,代码行数:35,代码来源:ResourceOwnerClient.cs

示例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;
 }
开发者ID:mequanta,项目名称:Janitor-old,代码行数:8,代码来源:Program.cs

示例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;
        }
开发者ID:NasC0,项目名称:LeagueComparer,代码行数:8,代码来源:Program.cs

示例4: RequestToken

        static TokenResponse RequestToken()
        {
            var client = new TokenClient(
                Constants.TokenEndpoint,
                "roclient.reference",
                "secret");

            return client.RequestResourceOwnerPasswordAsync("bob", "bob", "api1").Result;
        }
开发者ID:lurumad,项目名称:IdentityServer4.Samples,代码行数:9,代码来源:Program.cs

示例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;
        }
开发者ID:camainc,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs

示例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;
        }
开发者ID:okusnadi,项目名称:oauth2-simple,代码行数:12,代码来源:Program.cs

示例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;
        }
开发者ID:ryanmar,项目名称:IdentityServer3.Samples,代码行数:9,代码来源:Program.cs

示例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;
        }
开发者ID:wooboo,项目名称:WishlistApi,代码行数:10,代码来源:Program.cs

示例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
            });
        }
开发者ID:robinvanderknaap,项目名称:SkaeleAuthorizationServer,代码行数:11,代码来源:AuthenticateController.cs

示例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);
        }
开发者ID:mindfulsoftware,项目名称:oauth2Demo,代码行数:12,代码来源:AccountController.cs

示例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;
        }
开发者ID:camainc,项目名称:IdentityServer3.Samples,代码行数:12,代码来源:Program.cs

示例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;
        }
开发者ID:EinarLogi,项目名称:Web-Services,代码行数:16,代码来源:Program.cs

示例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;
                }
            }
        }
开发者ID:Agrando,项目名称:IdentityServer.Contrib.RavenDB,代码行数:18,代码来源:Program.cs

示例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);
        }
开发者ID:284247028,项目名称:IdentityServer3,代码行数:21,代码来源:UserInfoClient.cs

示例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);
        }
开发者ID:xyting,项目名称:RigoFunc.Account,代码行数:21,代码来源:DefaultAccessTokenProvider.cs


注:本文中的IdentityModel.Client.TokenClient.RequestResourceOwnerPasswordAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。