1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-31 06:40:39 +00:00

improve sso to thirdpart (#5420)

This commit is contained in:
WJH 2023-04-04 10:45:03 +08:00 committed by GitHub
parent 93afb46ed0
commit f584902e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 15 deletions

View File

@ -122,7 +122,7 @@ class Account extends Component {
};
} else if (isOrgStaff) {
data = {
url: enableSSOToThirdpartWebsite ? `${siteRoot}sso-to-thirdpart/` : `${siteRoot}org/info/`,
url: `${siteRoot}org/info/`,
text: gettext('Organization Admin')
};
} else if (isInstAdmin) {
@ -165,6 +165,7 @@ class Account extends Component {
</div>
<a href={siteRoot + 'profile/'} className="item">{gettext('Settings')}</a>
{this.renderMenu()}
{enableSSOToThirdpartWebsite && <a href={siteRoot + 'sso-to-thirdpart/'} className="item">{gettext('Customer Portal')}</a>}
<a href={siteRoot + 'accounts/logout/'} className="item">{gettext('Log out')}</a>
</div>
</div>

View File

@ -7,7 +7,6 @@ from django.http import HttpResponseRedirect
from seahub.auth.decorators import login_required
from seahub.utils import render_error
from seahub.api2.models import Token
try:
from seahub.settings import ENABLE_SSO_TO_THIRDPART_WEBSITE, THIRDPART_WEBSITE_SECRET_KEY, THIRDPART_WEBSITE_URL
except ImportError:
@ -24,20 +23,9 @@ def sso_to_thirdpart(request):
return render_error(request, 'Feature is not enabled.')
username = request.user.username
payload = {'exp': int(time.time()) + 30, 'user_id': username}
try:
api_token, _ = Token.objects.get_or_create(user=username)
except Exception as e:
logger.error(e)
return render_error(request, 'Internal Server Error')
payload = {
'exp': int(time.time()) + 100,
'user_id': username,
'api_token': api_token.key,
}
try:
access_token = jwt.encode(payload, THIRDPART_WEBSITE_SECRET_KEY, algorithm='HS256')
access_token = jwt.encode(payload, THIRDPART_WEBSITE_SECRET_KEY, algorithm='HS512')
except Exception as e:
logger.error(e)
return render_error(request, 'Internal Server Error')