public async Task Can_start_device_flow_and_request_token_using_device_code() { // Replace domain and clientId with the correct values. // Ensure Device Code Grant is enabled. var domain = ""; var clientId = ""; var request = new DeviceCodeRequest { ClientId = clientId, Scope = "openid profile" }; var authenticationApiClient = new AuthenticationApiClient(domain); var response = await authenticationApiClient.StartDeviceFlowAsync(request); response.Should().NotBeNull(); // Visit response.VerificationUriComplete and confirm the code before continuing. Debugger.Break(); var tokenReponse = await authenticationApiClient.GetTokenAsync(new DeviceCodeTokenRequest { ClientId = clientId, DeviceCode = response.DeviceCode }); tokenReponse.Should().NotBeNull(); }
public async Task Can_start_device_flow() { var mockHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict); var deviceCode = "TEST_CODE"; var response = new DeviceCodeResponse { DeviceCode = deviceCode }; var domain = GetVariable("AUTH0_AUTHENTICATION_API_URL"); var expectedParams = new Dictionary <string, string> { { "audience", "Test" }, { "scope", "openid profile" }, { "client_id", GetVariable("AUTH0_CLIENT_ID") } }; mockHandler.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.Is <HttpRequestMessage>(req => req.RequestUri.ToString() == $"https://{domain}/oauth/device/code" && ValidateRequestContent(req, expectedParams)), ItExpr.IsAny <CancellationToken>() ) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json"), }); var httpClient = new HttpClient(mockHandler.Object); var authenticationApiClient = new AuthenticationApiClient(domain, new HttpClientAuthenticationConnection(httpClient)); var tokenReponse = await authenticationApiClient.StartDeviceFlowAsync(new DeviceCodeRequest { ClientId = GetVariable("AUTH0_CLIENT_ID"), Scope = "openid profile", Audience = "Test" }); tokenReponse.Should().NotBeNull(); tokenReponse.DeviceCode.Should().Equals(deviceCode); }