How to use the taskcluster-lib-scopes.scopesSatisfying function in taskcluster-lib-scopes

To help you get started, we’ve selected a few taskcluster-lib-scopes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskcluster / taskcluster / libraries / api / src / middleware / auth.js View on Github external
// If authentication failed
        if (result.status === 'auth-failed') {
          res.set('www-authenticate', 'hawk');
          throw new ErrorReply({
            code: 'AuthenticationFailed',
            message: result.message,
            details: result,
          });
        }

        // Render the scope expression template
        const scopeExpression = scopeTemplate.render(params);

        // Test that we have scope intersection, and hence, is authorized
        const satisfyingScopes = !scopeExpression || scopes.scopesSatisfying(result.scopes, scopeExpression);
        req.hasAuthed = true;

        if (!satisfyingScopes) {
          const clientId = await req.clientId();
          throw new ErrorReply({
            code: 'InsufficientScopes',
            message: [
              'Client ID ' + clientId + ' does not have sufficient scopes and are missing the following scopes:',
              '',
              '```',
              '{{unsatisfied}}',
              '```',
              '',
              'You have the scopes:',
              '',
              '```',