mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 18:53:21 +01:00
write DeviantArt refresh-tokens to cache (#616)
Writing the token is currently disabled by default and must be enabled with 'extractor.oauth.cache'. 'extractor.deviantart.refresh-token' must be set to '"cache"' to use the cached token.
This commit is contained in:
parent
2a4f227e08
commit
913b8333cc
@ -961,11 +961,15 @@ class DeviantartAPI():
|
||||
self.folders = extractor.config("folders", False)
|
||||
self.metadata = extractor.extra or extractor.config("metadata", False)
|
||||
|
||||
self.refresh_token = extractor.config("refresh-token")
|
||||
self.client_id = extractor.config("client-id", self.CLIENT_ID)
|
||||
self.client_id = extractor.config(
|
||||
"client-id", self.CLIENT_ID)
|
||||
self.client_secret = extractor.config(
|
||||
"client-secret", self.CLIENT_SECRET)
|
||||
|
||||
self.refresh_token = extractor.config("refresh-token")
|
||||
if self.refresh_token == "cache":
|
||||
self.refresh_token = "#" + str(self.client_id)
|
||||
|
||||
self.log.debug(
|
||||
"Using %s API credentials (client-id %s)",
|
||||
"default" if self.client_id == self.CLIENT_ID else "custom",
|
||||
|
@ -98,7 +98,7 @@ class OAuthBase(Extractor):
|
||||
def _oauth2_authorization_code_grant(
|
||||
self, client_id, client_secret, auth_url, token_url,
|
||||
scope="read", key="refresh_token", auth=True,
|
||||
message_template=None):
|
||||
message_template=None, cache=None):
|
||||
"""Perform an OAuth2 authorization code grant"""
|
||||
|
||||
state = "gallery-dl_{}_{}".format(
|
||||
@ -162,6 +162,11 @@ class OAuthBase(Extractor):
|
||||
client_secret=client_secret,
|
||||
))
|
||||
|
||||
# write to cache
|
||||
if cache and config.get(("extractor", self.category), "cache"):
|
||||
cache.update("#" + str(client_id), data[key])
|
||||
self.log.info("Writing 'refresh-token' to cache")
|
||||
|
||||
|
||||
class OAuthDeviantart(OAuthBase):
|
||||
subcategory = "deviantart"
|
||||
@ -179,6 +184,7 @@ class OAuthDeviantart(OAuthBase):
|
||||
"https://www.deviantart.com/oauth2/authorize",
|
||||
"https://www.deviantart.com/oauth2/token",
|
||||
scope="browse",
|
||||
cache=deviantart._refresh_token_cache,
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user