public static function getInstance($key)
    {
        if (isset(self::$instances[$key])) {
            return self::$instances;
        }

        $oauth2Config = OAuth2::getConfig()->get($key, false);

        if (!$oauth2Config) {
            throw new OAuth2Exception('Unable to read "OAuth2.' . $key . '" configuration.');
        }

        if (self::str($oauth2Config->RedirectUri)->startsWith('http')) {
            $redirectUri = $oauth2Config->RedirectUri;
        } else {
            $redirectUri = self::httpRequest()
                               ->getCurrentUrl(true)
                               ->setPath($oauth2Config->RedirectUri)
                               ->setQuery('')
                               ->val();
        }

        $instance = Bridge\OAuth2::getInstance($oauth2Config->ClientId, $oauth2Config->ClientSecret, $redirectUri);

        $server = $oauth2Config->get('Server', false);
        if (!$server) {
            throw new OAuth2Exception('Server missing for "OAuth2.' . $key . '" configuration.');
        }

        $instance->setOAuth2Server($server);
        $instance->setScope($oauth2Config->get('Scope', ''));

        return new OAuth2($instance);
    }