public AzureTableStoreCoreSettings(IdentityServerTableContext context, string issuerUri, string siteName, string certificateThumbprint, string publicHostAddress) { _issuerUri = issuerUri; _siteName = siteName; _certificate = X509.LocalMachine.My.Thumbprint.Find(certificateThumbprint, false).First(); _publicHostAddress = publicHostAddress; this.context = context; }
public async Task TestMethod1() { IdentityServerTableContext storageContext = new IdentityServerTableContext( new CloudStorageAccount(new StorageCredentials("c1azuretests", File.ReadAllText("C:\\dev\\storagekey.txt")), true)); storageContext.InsertionMode = SInnovations.Azure.TableStorageRepository.InsertionMode.AddOrReplace; var localClients = GetClients().ToArray(); var localScopes = GetScopes().ToArray(); foreach (var client in localClients) { storageContext.Clients.Add(client); } foreach (var scope in localScopes) { storageContext.Scopes.Add(scope); } await storageContext.SaveChangesAsync(); var clients = (from ent in storageContext.Clients select ent).ToArray(); foreach (var client in localClients) { var remoteClient = clients.Single(c => c.ClientId == client.ClientId); Assert.AreEqual(client.AccessTokenLifetime, remoteClient.AccessTokenLifetime); Assert.AreEqual(client.AccessTokenType, remoteClient.AccessTokenType); Assert.AreEqual(client.AllowRememberConsent, remoteClient.AllowRememberConsent); Assert.AreEqual(client.ApplicationType, remoteClient.ApplicationType); Assert.AreEqual(client.AuthorizationCodeLifetime, remoteClient.AuthorizationCodeLifetime); Assert.AreEqual(client.ClientName, remoteClient.ClientName); Assert.AreEqual(client.ClientSecret, remoteClient.ClientSecret); Assert.AreEqual(client.ClientUri, remoteClient.ClientUri); Assert.AreEqual(client.Flow, remoteClient.Flow); Assert.AreEqual(client.IdentityTokenLifetime, remoteClient.IdentityTokenLifetime); Assert.AreEqual(client.IdentityTokenSigningKeyType, remoteClient.IdentityTokenSigningKeyType); Assert.AreEqual(client.LogoUri, remoteClient.LogoUri); CollectionAssert.AreEqual(client.RedirectUris, remoteClient.RedirectUris); Assert.AreEqual(client.RefreshTokenLifetime, remoteClient.RefreshTokenLifetime); Assert.AreEqual(client.RequireConsent, remoteClient.RequireConsent); CollectionAssert.AreEqual(client.ScopeRestrictions, remoteClient.ScopeRestrictions); Assert.AreEqual(client.SectorIdentifierUri, remoteClient.SectorIdentifierUri); Assert.AreEqual(client.SubjectType, remoteClient.SubjectType); } var scopes = (from ent in storageContext.Scopes select ent).ToArray(); foreach (var scope in localScopes) { var remoteScope = scopes.Single(c => c.Name == scope.Name); Assert.AreEqual(scope.Description, remoteScope.Description); Assert.AreEqual(scope.DisplayName, remoteScope.DisplayName); Assert.AreEqual(scope.Emphasize, remoteScope.Emphasize); Assert.AreEqual(scope.IsOpenIdScope, remoteScope.IsOpenIdScope); CollectionAssert.AreEqual(new List<ScopeClaim>(scope.Claims ?? new ScopeClaim[] { }), new List<ScopeClaim>(remoteScope.Claims ?? new ScopeClaim[] { }), new ScopeClaimComparer()); Assert.AreEqual(scope.Required, remoteScope.Required); } var subject = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]{ new Claim("name","poul") }, "Google", "MyName", "MyROle")); var code = new AuthorizationCode { Client = clients.First(), IsOpenId = true, RedirectUri = new Uri("http://www.s-innovations.net"), Subject = subject, RequestedScopes = scopes.Take(3), CreationTime = DateTime.UtcNow }; AzureTableStoreAuthorizationCodeStore store = new AzureTableStoreAuthorizationCodeStore(storageContext); await store.StoreAsync("test", code); var remotecode = await store.GetAsync("test"); Trace.TraceInformation(string.Join(", ", remotecode.Subject.Claims.Select(c => c.Type + "," + c.Value))); Assert.AreEqual(code.Client.ClientId, remotecode.Client.ClientId); Assert.AreEqual(code.CreationTime, remotecode.CreationTime); Assert.AreEqual(code.Subject.Identities.Count(), remotecode.Subject.Identities.Count()); try { await store.GetAsync("test"); Assert.Fail("test should have been removed"); } catch (Exception ex) { Trace.TraceInformation(ex.ToString()); } AzureTableStoreTokenHandlerStore tokens = new AzureTableStoreTokenHandlerStore(storageContext); await tokens.StoreAsync("testtoken", new Token("blabla") { Lifetime = 120, Audience = "asda", Issuer = "adsa", Client = clients.First() }); var token = await tokens.GetAsync("testtoken"); }