diff --git a/auth.py b/auth.py index ef4940240..eb25035d5 100644 --- a/auth.py +++ b/auth.py @@ -148,37 +148,6 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str, return False -def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [], - baseDir: str) -> None: - """Generates tokens for shared item federated domains - """ - if not sharedItemsFederatedDomains: - return - tokensFile = baseDir + '/accounts/sharedItemsFederationTokens' - if not os.path.isfile(tokensFile): - with open(tokensFile, 'w+') as fp: - fp.write('') - tokens = [] - with open(tokensFile, 'r') as fp: - tokens = fp.read().split('\n') - tokensAdded = False - for domain in sharedItemsFederatedDomains: - domainFound = False - for line in tokens: - if line.startswith(domain + ':'): - domainFound = True - break - if not domainFound: - newLine = domain + ':' + secrets.token_urlsafe(64) - tokens.append(newLine) - tokensAdded = True - if not tokensAdded: - return - with open(tokensFile, 'w+') as fp: - for line in tokens: - fp.write(line + '\n') - - def authorizeSharedItems(sharedItemsFederatedDomains: [], baseDir: str, callingDomain: str, diff --git a/daemon.py b/daemon.py index abf126b91..89b656329 100644 --- a/daemon.py +++ b/daemon.py @@ -103,7 +103,6 @@ from skills import noOfActorSkills from skills import actorHasSkill from skills import actorSkillValue from skills import setActorSkillLevel -from auth import generateSharedItemFederationTokens from auth import recordLoginFailure from auth import authorize from auth import authorizeSharedItems @@ -205,6 +204,7 @@ from webapp_welcome import htmlWelcomeScreen from webapp_welcome import isWelcomeScreenComplete from webapp_welcome_profile import htmlWelcomeProfile from webapp_welcome_final import htmlWelcomeFinal +from shares import generateSharedItemFederationTokens from shares import getSharesFeedForPerson from shares import addShare from shares import removeSharedItem diff --git a/shares.py b/shares.py index 06da0eef1..dc25b10bb 100644 --- a/shares.py +++ b/shares.py @@ -9,6 +9,7 @@ __module_group__ = "Timeline" import os import re +import secrets import time import datetime from webfinger import webfingerHandle @@ -940,3 +941,34 @@ def sharesCatalogCSVEndpoint(baseDir: str, httpPrefix: str, csvStr += item['DFC:Image'] + ',' csvStr += item['DFC:description'] + '\n' return csvStr + + +def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [], + baseDir: str) -> None: + """Generates tokens for shared item federated domains + """ + if not sharedItemsFederatedDomains: + return + tokensFile = baseDir + '/accounts/sharedItemsFederationTokens' + if not os.path.isfile(tokensFile): + with open(tokensFile, 'w+') as fp: + fp.write('') + tokens = [] + with open(tokensFile, 'r') as fp: + tokens = fp.read().split('\n') + tokensAdded = False + for domain in sharedItemsFederatedDomains: + domainFound = False + for line in tokens: + if line.startswith(domain + ':'): + domainFound = True + break + if not domainFound: + newLine = domain + ':' + secrets.token_urlsafe(64) + tokens.append(newLine) + tokensAdded = True + if not tokensAdded: + return + with open(tokensFile, 'w+') as fp: + for line in tokens: + fp.write(line + '\n')