mirror of https://gitlab.com/bashrc2/epicyon
Move token generation function
parent
47575a52a7
commit
646254c8a9
31
auth.py
31
auth.py
|
@ -148,37 +148,6 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
|
||||||
return False
|
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: [],
|
def authorizeSharedItems(sharedItemsFederatedDomains: [],
|
||||||
baseDir: str,
|
baseDir: str,
|
||||||
callingDomain: str,
|
callingDomain: str,
|
||||||
|
|
|
@ -103,7 +103,6 @@ from skills import noOfActorSkills
|
||||||
from skills import actorHasSkill
|
from skills import actorHasSkill
|
||||||
from skills import actorSkillValue
|
from skills import actorSkillValue
|
||||||
from skills import setActorSkillLevel
|
from skills import setActorSkillLevel
|
||||||
from auth import generateSharedItemFederationTokens
|
|
||||||
from auth import recordLoginFailure
|
from auth import recordLoginFailure
|
||||||
from auth import authorize
|
from auth import authorize
|
||||||
from auth import authorizeSharedItems
|
from auth import authorizeSharedItems
|
||||||
|
@ -205,6 +204,7 @@ from webapp_welcome import htmlWelcomeScreen
|
||||||
from webapp_welcome import isWelcomeScreenComplete
|
from webapp_welcome import isWelcomeScreenComplete
|
||||||
from webapp_welcome_profile import htmlWelcomeProfile
|
from webapp_welcome_profile import htmlWelcomeProfile
|
||||||
from webapp_welcome_final import htmlWelcomeFinal
|
from webapp_welcome_final import htmlWelcomeFinal
|
||||||
|
from shares import generateSharedItemFederationTokens
|
||||||
from shares import getSharesFeedForPerson
|
from shares import getSharesFeedForPerson
|
||||||
from shares import addShare
|
from shares import addShare
|
||||||
from shares import removeSharedItem
|
from shares import removeSharedItem
|
||||||
|
|
32
shares.py
32
shares.py
|
@ -9,6 +9,7 @@ __module_group__ = "Timeline"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import secrets
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
|
@ -940,3 +941,34 @@ def sharesCatalogCSVEndpoint(baseDir: str, httpPrefix: str,
|
||||||
csvStr += item['DFC:Image'] + ','
|
csvStr += item['DFC:Image'] + ','
|
||||||
csvStr += item['DFC:description'] + '\n'
|
csvStr += item['DFC:description'] + '\n'
|
||||||
return csvStr
|
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')
|
||||||
|
|
Loading…
Reference in New Issue