Beispiel #1
0
    def instance_host(self, value):
        self.instance_host_backend.set(self, value)

        instance_config = self.credentials
        self.client_id = instance_config.get("client_id")

        invalidate_cached_property(self, "session")
Beispiel #2
0
 def token(self, value):
     _token = value
     if _token and _token.get("expires_in"):
         # Set the `expires_at` value, overwriting any value
         # that may already be there.
         delta = timedelta(seconds=_token["expires_in"])
         expires_at = datetime.utcnow() + delta
         _token["expires_at"] = timestamp_from_datetime(expires_at)
     self.storage.set(self, _token)
     invalidate_cached_property(self.session, "token")
Beispiel #3
0
 def token(self, value):
     _token = value
     if _token and _token.get("expires_in"):
         # Set the `expires_at` value, overwriting any value
         # that may already be there.
         delta = timedelta(seconds=_token["expires_in"])
         expires_at = datetime.utcnow() + delta
         _token["expires_at"] = timestamp_from_datetime(expires_at)
     self.storage.set(self, _token)
     invalidate_cached_property(self.session, "token")
Beispiel #4
0
    def __init__(
        self,
        name,
        import_name,
        static_folder=None,
        static_url_path=None,
        template_folder=None,
        url_prefix=None,
        subdomain=None,
        url_defaults=None,
        root_path=None,
        login_url=None,
        authorized_url=None,
        storage=None,
    ):

        bp_kwargs = dict(
            name=name,
            import_name=import_name,
            static_folder=static_folder,
            static_url_path=static_url_path,
            template_folder=template_folder,
            url_prefix=url_prefix,
            subdomain=subdomain,
            url_defaults=url_defaults,
            root_path=root_path,
        )
        # `root_path` didn't exist in 0.10, and will cause an error if it's
        # passed in that version. Only pass `root_path` if it's set.
        if bp_kwargs["root_path"] is None:
            del bp_kwargs["root_path"]
        flask.Blueprint.__init__(self, **bp_kwargs)

        login_url = login_url or "/{bp.name}"
        authorized_url = authorized_url or "/{bp.name}/authorized"

        self.add_url_rule(rule=login_url.format(bp=self),
                          endpoint="login",
                          view_func=self.login)
        self.add_url_rule(
            rule=authorized_url.format(bp=self),
            endpoint="authorized",
            view_func=self.authorized,
        )

        if storage is None:
            self.storage = SessionStorage()
        elif callable(storage):
            self.storage = storage()
        else:
            self.storage = storage

        self.logged_in_funcs = []
        self.from_config = {}
        invalidate_token = lambda d: invalidate_cached_property(
            self.session, "token")
        self.config = CallbackDict(on_update=invalidate_token)
        self.before_app_request(self.load_config)
Beispiel #5
0
    def __init__(
        self,
        name,
        import_name,
        static_folder=None,
        static_url_path=None,
        template_folder=None,
        url_prefix=None,
        subdomain=None,
        url_defaults=None,
        root_path=None,
        login_url=None,
        authorized_url=None,
        storage=None,
    ):

        bp_kwargs = dict(
            name=name,
            import_name=import_name,
            static_folder=static_folder,
            static_url_path=static_url_path,
            template_folder=template_folder,
            url_prefix=url_prefix,
            subdomain=subdomain,
            url_defaults=url_defaults,
            root_path=root_path,
        )
        # `root_path` didn't exist in 0.10, and will cause an error if it's
        # passed in that version. Only pass `root_path` if it's set.
        if bp_kwargs["root_path"] is None:
            del bp_kwargs["root_path"]
        flask.Blueprint.__init__(self, **bp_kwargs)

        login_url = login_url or "/{bp.name}"
        authorized_url = authorized_url or "/{bp.name}/authorized"

        self.add_url_rule(
            rule=login_url.format(bp=self), endpoint="login", view_func=self.login
        )
        self.add_url_rule(
            rule=authorized_url.format(bp=self),
            endpoint="authorized",
            view_func=self.authorized,
        )

        if storage is None:
            self.storage = SessionStorage()
        elif callable(storage):
            self.storage = storage()
        else:
            self.storage = storage

        self.logged_in_funcs = []
        self.from_config = {}
        invalidate_token = lambda d: invalidate_cached_property(self.session, "token")
        self.config = CallbackDict(on_update=invalidate_token)
        self.before_app_request(self.load_config)
Beispiel #6
0
 def teardown_session(self, exception=None):
     invalidate_cached_property(self, "session")
Beispiel #7
0
 def invalidate_token(d):
     try:
         invalidate_cached_property(self.session, "token")
     except KeyError:
         pass
Beispiel #8
0
 def token(self):
     self.storage.delete(self)
     try:
         invalidate_cached_property(self.session, "token")
     except KeyError:
         pass
Beispiel #9
0
 def teardown_session(self, exception=None):
     try:
         invalidate_cached_property(self, "session")
     except KeyError:
         pass
Beispiel #10
0
 def teardown_session(self, exception=None):
     invalidate_cached_property(self, "session")
Beispiel #11
0
 def token(self):
     self.storage.delete(self)
     invalidate_cached_property(self.session, "token")
Beispiel #12
0
 def __init__(self, blueprint=None, base_url=None, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.blueprint = blueprint
     self.base_url = URLObject(base_url)
     invalidate_cached_property(self, "token")
Beispiel #13
0
 def __init__(self, blueprint=None, base_url=None, *args, **kwargs):
     super(OAuth2Session, self).__init__(*args, **kwargs)
     self.blueprint = blueprint
     self.base_url = URLObject(base_url)
     invalidate_cached_property(self, "token")
Beispiel #14
0
 def token(self):
     self.storage.delete(self)
     invalidate_cached_property(self.session, "token")
Beispiel #15
0
 def instance_host(self):
     self.instance_host_backend.delete(self)
     invalidate_cached_property(self, "session")