public void AddScope(string scope) { _namedScopes[scope] = scope; if (!Scopes.Contains(scope)) { Scopes.Add(scope); } }
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"); } } }
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"); } }
public void AddScopes(List <string> scopes) { foreach (string scope in scopes) { _namedScopes[scope] = scope; if (!Scopes.Contains(scope)) { Scopes.Add(scope); } } }
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"); } }
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); }
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); }
public virtual bool InScope(string scope) => string.IsNullOrWhiteSpace(scope) || Scopes.Contains(scope, StringComparer.InvariantCultureIgnoreCase);