public override void Customize(IFixture fixture) { base.Customize(fixture); Fixture fixtureUser = new Fixture(); fixtureUser.Customize(new UserCustomization()); var user = fixtureUser.Create <User>(); Fixture fixtureClient = new Fixture(); fixtureClient.Customize(new ClientCustomization()); var client = fixtureClient.Create <Client>(); fixture.Customize <Identity>(e => e .Without(p => p.User) .Without(p => p.Client) .Without(p => p.Access) .Without(p => p.Refresh) .Do(o => { o.User = user; o.Client = client; o.Access = JwtTokenizer.Encode(o.User.Credential.ApiKey.Key, o.Client.ApiKey.Key, 10); o.Refresh = JwtTokenizer.Encode(o.User.Credential.ApiKey.Key, o.Client.ApiKey.Key, 100); })); }
public Identity CreateIdentity( User user = null, Client client = null, bool push = true) { var fixture = new Fixture(); fixture.Customize(new IdentityCustomization()); user = user ?? this.CreateUser(); client = client ?? this.CreateClient(); var identity = fixture.Create <Identity>(); identity.User = user; identity.Client = client; identity.Access = JwtTokenizer.Encode(identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, 5); identity.Refresh = JwtTokenizer.Encode(identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, 1000); if (!push) { return(identity); } using (var repository = this.CreateRepository <Identity>(this.Context, false)) { repository.Insert(identity); repository.Commit(); } return(identity); }
protected void GetToken(Identity identity) { identity.Access = JwtTokenizer.Encode( identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, this._expirationTimeAccess); identity.Refresh = JwtTokenizer.Encode( identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, this._expirationTimeRefresh); }
public void Refresh_WithExpiredToken() { var identity = this.CreateIdentity(); identity.Access = JwtTokenizer.Encode(identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, -0.01); identity.Refresh = JwtTokenizer.Encode(identity.User.Credential.ApiKey.Key, identity.Client.ApiKey.Key, -0.01); this.CreateAuthentifiedUser(identity); var request = this.CreateRequest(HttpMethod.Get, uriEndPoint: "refresh"); var response = this.Client.SendAsync(request).Result; Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode); }