Auth phase (when we have the ID token):
326782
@Override
    public boolean authorizeURLRequest(Request.Builder builder) {
        loadTokens();
        if (IDToken != null && !haveSessionCookie) {
            String auth = String.format(Locale.ENGLISH, "Bearer ", IDToken);
            builder.addHeader("Authorization", auth);
            return true;
        } else {
            return false;
        }
    }
1202423
function authNeeded () {

    if (args.write === true) {
      return true
    }

    if (args.channel.indexOf('private-') === 0) {
      return true
    }

    if (args.channel.indexOf('presence-') === 0) {
      return true
    }

    return false;
  }
905367
function setAuth(authData) {
    exports.authHeaders['X-Auth-Token'] = authData.authToken;
    exports.authHeaders['X-User-Id'] = authData.userId;
}
955042
def _check_authorization(cls, authzr, identifier):
        
        if authzr.body.identifier != identifier:
            raise errors.UnexpectedUpdate(authzr)
        return authzr
47241
def issue_token(kind)
      session = Session.new(user: self, seconds: 3600)
      session.save
      if kind == :reset_token
        self.reset_token = session.token
      elsif kind == :verification_token
        self.verification_token = session.token
      end
    end
657984
function getIdToken(forceRefresh) {
  if (activeUser() == null) {
    alertError('No user logged in.');
    return;
  }
  if (activeUser().getIdToken) {
    activeUser().getIdToken(forceRefresh).then(alertSuccess, function() {
      log("No token");
    });
  } else {
    activeUser().getToken(forceRefresh).then(alertSuccess, function() {
      log("No token");
    });
  }
}
1166017
function authDetectionMiddleware(req, res, next) {
    logger.debug('Running Auth Detection Middleware...', req.body);

    if (req.headers['token']) {
      try {
        req.user = encryption.decode(req.headers['token'], config.secret);
        req.session = { user: req.user };
      } catch (ex) {
        logger.logError('Unexpectedly could not decode a token.', ex);
        res.status(401).send();
        // ensure no user is authenticated.
        req.user = null;
        req.session = { user: null };
      }
      if (!req.user.id) throw 'AUTH FAILED:USER HAS NO MEMBER: id';
      if (!req.user.tokenExpiry || req.user.tokenExpiry <= new Date().getTime()) {
        logger.log('Expired Token:', req.user);
        res.status(401).send({errorCode: 'expired token'});
      }
      else {
        logger.log('Authenticated User:', req.user.id);
        next();
      }
    } else {
      //logger.debug('Checking permissions to ', req.path);
      //if (config.routesNotRequiringAuthentication[req.path]) next();
      //else if (m.isPublicRoute(req.path)) next();
      //else {
      //  logger.debug('Disallowing request to:', req.path);
      //  res.status(401).send();
      //}
      if (config.authenticatedRoutes[req.path] || !m.isPublicRoute(req.path))
        res.status(401).send();
      else
        next();
    }
  }
41846
def verify(self):
        
        # According to RFC 7519, the "exp" claim is OPTIONAL
        # (https://tools.ietf.org/html/rfc7519#section-4.1.4).  As a more
        # correct behavior for authorization tokens, we require an "exp"
        # claim.  We don't want any zombie tokens walking around.
        self.check_exp()

        # Ensure token id is present
        if api_settings.JTI_CLAIM not in self.payload:
            raise TokenError(_('Token has no id'))

        self.verify_token_type()
438284
@SuppressWarnings("unchecked")
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
            throws AuthenticationException {
        String id;

        if (AnonymousToken.isAnonymous(token)) {
            // Only continue if an anonymous identity has been set
            if (_anonymousId != null) {
                id = _anonymousId;
            } else {
                return null;
            }
        } else {
            id = ((ApiKeyAuthenticationToken) token).getPrincipal();
        }

        return getUncachedAuthenticationInfoForKey(id);
    }
331205
def userinfo_in_id_token_claims(endpoint_context, session, def_itc=None):
    
    if def_itc:
        itc = def_itc
    else:
        itc = {}

    itc.update(id_token_claims(session))

    if not itc:
        return None

    _claims = by_schema(endpoint_context.id_token_schema, **itc)

    if _claims:
        return collect_user_info(endpoint_context, session, _claims)
    else:
        return None
1252579
private void configureStateAuth() {
        setIsControlEnable(authButton, false);
        if(isAuthenticated()) {
            authStatusLabel.setText(I18nLabelsLoader.ADDON_LOGIN_STATUS_OK);
            setDefaultButton(nextButtonName, true);
            if(userPasswordText.getText() != null && userPasswordText.getText().length() == 0) {
                userPasswordText.setText("********");
            }            
            setDefaultButton(authButton, false);
            setDefaultButton(cancelButtonName, false);
            setDefaultButton(nextButtonName, true);
        } else if (gotCommunicationError) {
            // leave previous state
            setIsControlEnable(authButton, true);
            setDefaultButton(cancelButtonName, true);
        }
    }
988395
function() {
        var authData = this.get('authData');
        if (!authData) {
          return;
        }
        var self = this;
        AV._objectEach(this.get('authData'), function(value, key) {
          self._logOutWith(key);
        });
      }
1006157
function DiscogsOAuth(auth){
	this.config = util.merge({}, defaultConfig);
	this.auth = {method: 'oauth', level: 0};
	if(auth && (typeof auth === 'object') && (auth.method === 'oauth')){
		util.merge(this.auth, auth);
	}
}
1022527
def on_authenticated(self, authorization):
        

        # Acquire condition
        self.is_authenticating.acquire()

        # Store authorization for future calls
        self.authorization = authorization

        print('Authentication successful - authorization: %r' % self.authorization)

        # Authentication complete
        self.is_authenticating.notify_all()
        self.is_authenticating.release()
338938
def token_get(profile=None, **connection_args):
    '''
    
    '''
    kstone = auth(profile, **connection_args)
    token = kstone.service_catalog.get_token()
    return {'id': token['id'],
            'expires': token['expires'],
            'user_id': token['user_id'],
            'tenant_id': token['tenant_id']}
332972
def auth_get_token(self, check_state=True):
		''
		res = self.auth_access_data_raw = yield self._auth_token_request()
		defer.returnValue(self._auth_token_process(res, check_state=check_state))
1034240
def auth_with_token(token, tenant_id=None, tenant_name=None, region=None):
    
    global regions, services
    identity.auth_with_token(token, tenant_id=tenant_id,
            tenant_name=tenant_name)
    regions = tuple(identity.regions)
    services = tuple(identity.services.keys())
    connect_to_services(region=region)