Decodes an OIDC issuer (`.iss`) url from an access token and returns it.
@param token {String} JWT Access Token (in encoded string form)
@return {String}
975021
function extractIssuer (token) {
  if (!token) {
    return
  }
  // Decode the JWT. Skip verification (since we need an issuer to verify)
  var claims = JWT.decode(token, null, { noVerify: true })
  return claims.payload.iss
}
962201
def _decrypt(self, rj, token):
        
        if self.iss:
            keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt, aud=self.iss)
        else:
            keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt)
        return rj.decrypt(token, keys=keys)
1143302
function getAuthorizeURL($token, $sign_in_with_twitter = TRUE)
    {
        if (is_array($token)) {
            $token = $token['oauth_token'];
        }
        if (empty($sign_in_with_twitter)) {
            return $this->authorizeURL() . "?oauth_token={$token}";
        } else {
            return $this->authenticateURL() . "?oauth_token={$token}";
        }
    }
1327044
def verify_token(self, token, **kwargs):
        """"""
        nonce = kwargs.get('nonce')

        token = force_bytes(token)
        if self.OIDC_RP_SIGN_ALGO.startswith('RS'):
            if self.OIDC_RP_IDP_SIGN_KEY is not None:
                key = self.OIDC_RP_IDP_SIGN_KEY
            else:
                key = self.retrieve_matching_jwk(token)
        else:
            key = self.OIDC_RP_CLIENT_SECRET

        payload_data = self.get_payload_data(token, key)

        # The 'token' will always be a byte string since it's
        # the result of base64.urlsafe_b64decode().
        # The payload is always the result of base64.urlsafe_b64decode().
        # In Python 3 and 2, that's always a byte string.
        # In Python3.6, the json.loads() function can accept a byte string
        # as it will automagically decode it to a unicode string before
        # deserializing https://bugs.python.org/issue17909
        payload = json.loads(payload_data.decode('utf-8'))
        token_nonce = payload.get('nonce')

        if self.get_settings('OIDC_USE_NONCE', True) and nonce != token_nonce:
            msg = 'JWT Nonce verification failed.'
            raise SuspiciousOperation(msg)
        return payload
458532
private AuthToken parseAuthorizationToken(String authHeader) {
        try {
            String tokenEncoded = authHeader.substring(11);
            return AuthTokenUtil.consumeToken(tokenEncoded);
        } catch (IllegalArgumentException e) {
            // TODO log this error
            return null;
        }
    }
590549
function Parse ( token ) {
  if ( typeof token != 'string' )
      throw new Error('JWT must be a string object')

  var parts = token.split('.')

  if (!parts.every(b64url.valid))
      throw new Error('JWT contains invalid URL safe Base64 chars')
  try {
    this.header = JSON.parse( b64url.decode( parts[0] ) )
  }
  catch (e) {
      return e
  }
  if (!this.header.typ)
      throw new Error('No "typ" in JWT header')

  if (this.header.typ == 'JWS') {
    try {
      this.payload = JSON.parse( b64url.decode( parts[1] ) )
    }
    catch (e) {
        return e
    }
    this._input = parts[0] +'.'+ parts[1]
    this.signature = parts[2]
    return this

  } else if (this.header.typ == 'JWE') {
    if (parts.length != 5)
      throw new Error('Invalid JWE token, does not have 5 components')
    this._input = parts[0] +'.'+ parts[1] +'.'+ parts[2] +'.'+ parts[3]
    this._cmk = parts[1]
    this._iv = parts[2]
    this._ciphertext = parts[3]
    this.signature = parts[4]
    return this

  } else
    throw new Error('Uknownn JWT header "typ":"'+this.header.typ+'"')
}
569581
function validateAskPermission (token) {
  const header = jwt.decode(token)

  return validateToken(token) && header[ASK_CLAIM_KEY]
}
494275
function extractToken(token) {
    var regex = /^Bearer\s(\S+)$/i;
    var result = regex.exec(token);
    return result ? result[1] : false;
}
817686
def core__decode_token token
      begin
        body = JWT.decode(token, Rails.application.secrets.secret_key_base,
                          true, algorithm: 'HS256')[0]
        return HashWithIndifferentAccess.new body
      rescue => exception
        return nil
      end
    end
712274
function getTokenFromHeader(request) {
  if (!request.headers || !request.headers.has('authorization')) {
    throw new UnauthorizedError('No authorization header present');
  }

  const parts = request.headers.get('authorization').split(" ");

  if (parts.length === 2) {
    const scheme = parts[0];
    const credentials = parts[1];

    if (/^Bearer$/i.test(scheme)) {
      return credentials;
    } else {
      throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
    }
  } else {
    throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
  }
}
532182
async function _verifyToken (jwksClient, token) {
  const decoded = jwt.decode(token, { complete: true })
  const signingKey = await jwksClient.getSigningKeyAsync(decoded.header.kid)
  return jwt.verifyAsync(token, signingKey.publicKey || signingKey.rsaPublicKey)
}
361810
def get_oauth_token():
    """"""
    url = "{0}/token".format(DEFAULT_ORIGIN["Origin"])
    r = s.get(url=url)
    return r.json()["t"]
741778
function generateBearerToken(tokenSecret, expiresInMinutes = 60 * 24 * 14, scope = []) {
  if (!tokenSecret) {
    throw new Error('Token secret is undefined');
  }

  const data = {
    user: this._id.toString(),
  };

  if (scope.length) {
    data.scope = scope;
  }

  const token = jwt.sign(data, tokenSecret, {
    expiresInMinutes,
  });

  return {
    type: 'Bearer',
    value: token,
  };
}
1277621
function decodeToken (tokenStr) {
  if (!tokenStr || tokenStr === '') return null
  try {
    return jwtDecode(tokenStr)
  } catch (error) {
    logger.error({
      description: 'Error decoding token.',
      error, func: 'decodeToken', file: 'token'
    })
    return null
  }
}
566561
def get_auth_token(self, user_payload):
        
        now = datetime.utcnow()
        payload = {
            'user': user_payload
        }
        if 'iat' in self.verify_claims:
            payload['iat'] = now

        if 'nbf' in self.verify_claims:
            payload['nbf'] = now + self.leeway

        if 'exp' in self.verify_claims:
            payload['exp'] = now + self.expiration_delta

        if self.audience is not None:
            payload['aud'] = self.audience

        if self.issuer is not None:
            payload['iss'] = self.issuer

        return jwt.encode(
            payload,
            self.secret_key,
            algorithm=self.algorithm,
            json_encoder=ExtendedJSONEncoder).decode('utf-8')
735920
def _decode_exp(self, access_token=None):
        
        c = self.get_credentials()
        jwt = access_token or c.access_token
        x = self.decode_jwt_payload(jwt)

        if 'exp' in x:
            try:
                exp = int(x['exp'])
            except ValueError:
                raise PanCloudError(
                    "Expiration time (exp) must be an integer")
            else:
                self.jwt_exp = exp
                return exp
        else:
            raise PanCloudError("No exp field found in payload")
874748
function getToken (token, callback) {

    if (token != null &&
        token != '') {

        // Fetch token from database or cache

        if (token == 'h328hdkasjd3') {

            var record = { algorithm: 'hmac-sha-256',   // Required
                secret: '23hdkdho2893hdkjd',            // Required
                userId: 'johndoe'                       // Application-specific field
            };

            callback(record);
        }
        else {

            // Token not found

            callback({});
        }
    }
    else {

        // Invalid token request

        callback({});
    }
}