예제 #1
0
        public string GetBearerToken(string username, string password, string scope)
        {
            using (System.Net.Http.HttpClient client = CreateClient())
            {
                DiscoveryResponse disco = client.GetDiscoveryDocumentAsync(Utils.ServerConfiguration.Identity).Result;
                Assert.IsFalse(disco.IsError);

                TokenResponse tokenResponse = client.RequestPasswordTokenAsync(new PasswordTokenRequest
                {
                    Address      = disco.TokenEndpoint,
                    ClientId     = MockIdentityWebApplicationFactory.ClientId,
                    ClientSecret = MockIdentityWebApplicationFactory.ClientSecret,

                    UserName = username,
                    Password = password,
                    Scope    = scope,
                }).Result;

                Assert.IsFalse(tokenResponse.IsError);
                return(tokenResponse.Json["access_token"].ToString());
            }
        }