public async Task <ActionResult> FindByCode(string userCode = null, string deviceCode = null) { if (string.IsNullOrWhiteSpace(userCode) && string.IsNullOrWhiteSpace(deviceCode)) { return(StatusCode(403)); } if (!string.IsNullOrWhiteSpace(userCode)) { return(Ok(await _store.FindByUserCodeAsync(userCode))); } return(Ok(await _store.FindByDeviceCodeAsync(deviceCode))); }
public async Task StoreDeviceAuthorizationAsync() { await _deviceFlowStore.StoreDeviceAuthorizationAsync( "DeviceCode-Test1", "UserCode-Test1", new DeviceCode { ClientId = "ClientId1", AuthorizedScopes = new string[] { "s1", "s2" }, IsAuthorized = true, Lifetime = 42, RequestedScopes = new string[] { "rs1" }, Subject = new ClaimsPrincipal( new[] { new ClaimsIdentity(new[] { new Claim(JwtClaimTypes.Subject, "sid1") }) } ) } ); void Check(DeviceCode deviceCode) { deviceCode.ClientId.ShouldBe("ClientId1"); deviceCode.AuthorizedScopes.ShouldNotBeNull(); deviceCode.AuthorizedScopes.Count().ShouldBe(2); deviceCode.AuthorizedScopes.ShouldContain("s1"); deviceCode.AuthorizedScopes.ShouldContain("s2"); deviceCode.IsAuthorized.ShouldBeTrue(); deviceCode.Lifetime.ShouldBe(42); deviceCode.RequestedScopes.ShouldNotBeNull(); deviceCode.RequestedScopes.Count().ShouldBe(1); deviceCode.RequestedScopes.ShouldContain("rs1"); deviceCode.Subject.ShouldNotBeNull(); deviceCode.Subject.Claims.ShouldContain(x => x.Type == JwtClaimTypes.Subject && x.Value == "sid1"); } Check(await _deviceFlowStore.FindByUserCodeAsync("UserCode-Test1")); Check(await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode-Test1")); }
/// <summary> /// Finds device authorization by user code. /// </summary> /// <param name="userCode">The user code.</param> /// <returns></returns> public Task <DeviceCode> FindByUserCodeAsync(string userCode) { return(_store.FindByUserCodeAsync(userCode.Sha256())); }
/// <summary> /// Finds device authorization by user code. /// </summary> /// <param name="userCode">The user code.</param> /// <returns></returns> public Task <DeviceCode> FindByUserCodeAsync(string userCode) { using var activity = Tracing.StoreActivitySource.StartActivity("DefaultDeviceFlowCodeService.FindByUserCode"); return(_store.FindByUserCodeAsync(userCode.Sha256())); }