/// <summary>Checks whether the AccessToken has the permissions for the given resource and scope.</summary>
        /// <param name="accessToken">this.</param>
        /// <returns>Returns true if the AccessToken has the permissions for the scopeName.</returns>
        public static List <Permission> GetPermissions(this AccessToken accessToken)
        {
            ResourceAuthorization authorization = accessToken.ResourceAuthorization !;

            if (authorization == null)
            {
                return(new List <Permission>());
            }

            List <Permission> list = authorization.Permissions !;

            return(new List <Permission>(list));
        }
Beispiel #2
0
        public void TestToString_PermissionIdUnknown()
        {
            var authorization = new ResourceAuthorization
            {
                ForeignResourceId = 1,
                IsAllowed         = true,
                PermissionId      = 0,
                PrincipalId       = 2,
                ResourceId        = 3,
                ResourceTypeId    = ResourceType.Project.Id
            };
            var s = authorization.ToString();

            Assert.IsNotNull(s);
        }
        /// <summary>Checks whether the AccessToken has the permissions for the given scope.</summary>
        /// <param name="accessToken">this.</param>
        /// <param name="scopeName">A resource name.</param>
        /// <returns>Returns true if the AccessToken has the permissions for the scopeName.</returns>
        public static bool HasScopePermission(this AccessToken accessToken, string scopeName)
        {
            ResourceAuthorization authorization = accessToken.ResourceAuthorization !;

            if (authorization != null)
            {
                foreach (Permission permission in authorization.Permissions !)
                {
                    if (permission.Scopes !.Contains(scopeName))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(false);
        }