mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-10 19:32:25 +00:00
improve sso to thirdpart (#5420)
This commit is contained in:
parent
93afb46ed0
commit
f584902e9c
@ -122,7 +122,7 @@ class Account extends Component {
|
|||||||
};
|
};
|
||||||
} else if (isOrgStaff) {
|
} else if (isOrgStaff) {
|
||||||
data = {
|
data = {
|
||||||
url: enableSSOToThirdpartWebsite ? `${siteRoot}sso-to-thirdpart/` : `${siteRoot}org/info/`,
|
url: `${siteRoot}org/info/`,
|
||||||
text: gettext('Organization Admin')
|
text: gettext('Organization Admin')
|
||||||
};
|
};
|
||||||
} else if (isInstAdmin) {
|
} else if (isInstAdmin) {
|
||||||
@ -165,6 +165,7 @@ class Account extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<a href={siteRoot + 'profile/'} className="item">{gettext('Settings')}</a>
|
<a href={siteRoot + 'profile/'} className="item">{gettext('Settings')}</a>
|
||||||
{this.renderMenu()}
|
{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>
|
<a href={siteRoot + 'accounts/logout/'} className="item">{gettext('Log out')}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,7 +7,6 @@ from django.http import HttpResponseRedirect
|
|||||||
|
|
||||||
from seahub.auth.decorators import login_required
|
from seahub.auth.decorators import login_required
|
||||||
from seahub.utils import render_error
|
from seahub.utils import render_error
|
||||||
from seahub.api2.models import Token
|
|
||||||
try:
|
try:
|
||||||
from seahub.settings import ENABLE_SSO_TO_THIRDPART_WEBSITE, THIRDPART_WEBSITE_SECRET_KEY, THIRDPART_WEBSITE_URL
|
from seahub.settings import ENABLE_SSO_TO_THIRDPART_WEBSITE, THIRDPART_WEBSITE_SECRET_KEY, THIRDPART_WEBSITE_URL
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -24,20 +23,9 @@ def sso_to_thirdpart(request):
|
|||||||
return render_error(request, 'Feature is not enabled.')
|
return render_error(request, 'Feature is not enabled.')
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
|
payload = {'exp': int(time.time()) + 30, 'user_id': username}
|
||||||
try:
|
try:
|
||||||
api_token, _ = Token.objects.get_or_create(user=username)
|
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')
|
|
||||||
|
|
||||||
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')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return render_error(request, 'Internal Server Error')
|
return render_error(request, 'Internal Server Error')
|
||||||
|
Loading…
Reference in New Issue
Block a user