TsgcWSAPIKeyManagerMethods › HasScope

HasScope Method

Returns True if the key carries the given scope.

Syntax

function HasScope(const aKey, aScope: string): Boolean;

Parameters

NameTypeDescription
aKeyconst stringRaw plaintext key to inspect (re-hashed internally to locate the entry).
aScopeconst stringCase-sensitive scope identifier to check for.

Return Value

True when the key exists, its scope list contains aScope, and the matching Scopes catalog entry is itself enabled. False in every other case (unknown key, scope absent, catalog entry disabled). (Boolean)

Remarks

Pure lookup, no side effects. Used internally by ValidateKey and IsRequestAuthorized when a aRequiredScope is supplied; you can also call it directly for fine-grained branches inside a request handler ("this endpoint needs write:orders, escalate error message if only read:orders is present"). A disabled Scopes.Scopes[x] entry causes HasScope to return False even when the scope is attached — that is how the catalog's own Enabled flag revokes a scope company-wide.

Example

if not sgcWSAPIKeyManager1.HasScope(vKey, 'write:orders') then
  Response.StatusCode := 403;

Back to Methods