public void OnAuthorization(AuthorizationFilterContext context) { var profile = AuthenticatedProfile.GetProfileForUser(context.HttpContext.User); if (profile.Type != _profileType) { context.Result = new ForbidResult(); } }
public void UserProfile_ShouldReturnServiceType_WhenAuthenticated_AndSubIsNull() { var principal = NewPrincipal(null, true); Assert.True(principal.Identity !.IsAuthenticated); var sut = AuthenticatedProfile.GetProfileForUser(principal); Assert.Equal(ProfileType.Service, sut.Type); }
public void UserProfile_ShouldHaveUserType_WhenAuthenticated(string sub) { var principal = NewPrincipal(sub, true); Assert.True(principal.Identity !.IsAuthenticated); var sut = AuthenticatedProfile.GetProfileForUser(principal); Assert.Equal(ProfileType.User, sut.Type); }
public void ServiceProfile_ShouldHaveAnonymousType_WhenNotAuthenticated() { var principal = NewPrincipal(null, false); Assert.False(principal.Identity !.IsAuthenticated); var sut = AuthenticatedProfile.GetProfileForUser(principal); Assert.Equal(ProfileType.Anonymous, sut.Type); }
private async Task <AuthenticatedProfile> DeserializeProfile(AuthenticationTableEntity authenticationTableEntity) { var authenticatedProfile = new AuthenticatedProfile(authenticationTableEntity); // If the token is closer to 5 minutes away from expiry // Then update the token and the userProfile. if (authenticationTableEntity.ExpiresAt <= DateTime.UtcNow.AddMinutes(-5)) { authenticatedProfile.Token = await GetTokenAsync(authenticatedProfile.Token.RefreshToken, refresh : true); authenticatedProfile.Profile = await GetUserProfileAsync(authenticatedProfile.Token); await SaveAuthenticatedProfileAsync(authenticatedProfile); } return(authenticatedProfile); }
public Task SaveAuthenticatedProfileAsync(AuthenticatedProfile authenticatedProfile) { return(SaveAuthenticatedProfileAsync(authenticatedProfile.ConversationId, authenticatedProfile.UserId, authenticatedProfile.Token, authenticatedProfile.Profile)); }
public AuthenticatedProfile GetProfile() => _claimsPrincipal == null ? throw new InvalidOperationException("Client is not authenticated yet.") : AuthenticatedProfile.GetProfileForUser(_claimsPrincipal);
public void AnonymousProfile_ShouldHaveAnonymousType() { var sut = AuthenticatedProfile.Anonymous(); Assert.Equal(ProfileType.Anonymous, sut.Type); }
public void ServiceProfile_ShouldHaveServiceType_WhenAuthenticated() { var sut = AuthenticatedProfile.ForService(); Assert.Equal(ProfileType.Service, sut.Type); }
public void AnonymousProfile_ShouldHaveAnonymousProfileId() { var sut = AuthenticatedProfile.Anonymous(); Assert.Equal(ProfileId.AnonymousUserId, sut.ProfileId); }
public void AnonymousProfile_ShouldNotBeAuthenticated() { var sut = AuthenticatedProfile.Anonymous(); Assert.False(sut.IsAuthenticated); }