예제 #1
0
    public void OnAuthorization(AuthorizationFilterContext context)
    {
        var profile = AuthenticatedProfile.GetProfileForUser(context.HttpContext.User);

        if (profile.Type != _profileType)
        {
            context.Result = new ForbidResult();
        }
    }
예제 #2
0
    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);
    }
예제 #3
0
    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);
    }
예제 #4
0
    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);
    }
예제 #5
0
        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);
        }
예제 #6
0
 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);
예제 #8
0
    public void AnonymousProfile_ShouldHaveAnonymousType()
    {
        var sut = AuthenticatedProfile.Anonymous();

        Assert.Equal(ProfileType.Anonymous, sut.Type);
    }
예제 #9
0
    public void ServiceProfile_ShouldHaveServiceType_WhenAuthenticated()
    {
        var sut = AuthenticatedProfile.ForService();

        Assert.Equal(ProfileType.Service, sut.Type);
    }
예제 #10
0
    public void AnonymousProfile_ShouldHaveAnonymousProfileId()
    {
        var sut = AuthenticatedProfile.Anonymous();

        Assert.Equal(ProfileId.AnonymousUserId, sut.ProfileId);
    }
예제 #11
0
    public void AnonymousProfile_ShouldNotBeAuthenticated()
    {
        var sut = AuthenticatedProfile.Anonymous();

        Assert.False(sut.IsAuthenticated);
    }