コード例 #1
0
 public void AddScope(string scope)
 {
     _namedScopes[scope] = scope;
     if (!Scopes.Contains(scope))
     {
         Scopes.Add(scope);
     }
 }
コード例 #2
0
 public void DynamicScopeValidation(Enums.AuthScopes requiredScope, string accessToken = null)
 {
     if (!Validators.SkipDynamicScopeValidation && accessToken == null)
     {
         if (!Scopes.Contains(requiredScope) || (requiredScope == Enums.AuthScopes.Any && Scopes.Count == 0))
         {
             throw new InvalidCredentialException($"The current access token ({Scopes.ToString()}) does not support this call. Missing required scope: {requiredScope.ToString().ToLower()}. You can skip this check by using: TwitchLib.TwitchAPI.Settings.Validators.SkipDynamicScopeValidation = true . You can also generate a new token with this scope here: https://twitchtokengenerator.com");
         }
     }
 }
コード例 #3
0
 public void ValidateScope(Enums.AuthScopes requiredScope, string accessToken = null)
 {
     if (accessToken != null)
     {
         return;
     }
     if (Scopes.Contains(requiredScope))
     {
         throw new Exceptions.API.InvalidCredentialException($"The call you attempted was blocked because you are missing required scope: {requiredScope.ToString().ToLower()}. You can ignore this protection by using TwitchLib.TwitchAPI.Settings.Validators.SkipDynamicScopeValidation = false . You can also generate a new token with the required scope here: https://twitchtokengenerator.com");
     }
 }
コード例 #4
0
 public void AddScopes(List <string> scopes)
 {
     foreach (string scope in scopes)
     {
         _namedScopes[scope] = scope;
         if (!Scopes.Contains(scope))
         {
             Scopes.Add(scope);
         }
     }
 }
コード例 #5
0
        public void DynamicScopeValidation(AuthScopes requiredScope, string accessToken = null)
        {
            if (Validators.SkipDynamicScopeValidation || !string.IsNullOrWhiteSpace(accessToken) || Scopes == null)
            {
                return;
            }

            if (!Scopes.Contains(requiredScope) || requiredScope == AuthScopes.Any && Scopes.Any(x => x == AuthScopes.None))
            {
                throw new InvalidCredentialException($"The current access token ({String.Join(",", Scopes)}) does not support this call. Missing required scope: {requiredScope.ToString().ToLower()}. You can skip this check by using: TwitchLib.TwitchAPI.Settings.Validators.SkipDynamicScopeValidation = true . You can also generate a new token with this scope here: https://twitchtokengenerator.com");
            }
        }
コード例 #6
0
 public bool CheckScopes(params string[] scopes)
 {
     if (!string.IsNullOrEmpty(Scopes))
     {
         bool inside = true;
         foreach (string scope in scopes)
         {
             inside &= Scopes.Contains(scope);
         }
         return(inside);
     }
     return(false);
 }
コード例 #7
0
        public OAuth2ResourceProvider AddRequestScope <TRequest>()
            where TRequest : OAuthRequest, new()
        {
            var request = new TRequest();

            foreach (var scope in request.RequiredScopes)
            {
                if (!AvailableScopes.Contains(scope))
                {
                    throw new InvalidScopeException(string.Format(
                                                        StringResources.ScopeException,
                                                        scope,
                                                        this.GetType().Name));
                }
                if (!Scopes.Contains(scope))
                {
                    Scopes.Add(scope);
                }
            }

            return(this);
        }
コード例 #8
0
 public virtual bool InScope(string scope) => string.IsNullOrWhiteSpace(scope) ||
 Scopes.Contains(scope, StringComparer.InvariantCultureIgnoreCase);