Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
feat: added OAuth login
Browse files Browse the repository at this point in the history
  • Loading branch information
akelch committed Mar 22, 2022
1 parent d2d3b29 commit 1249183
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This file documents any relevant changes done to ViUR Vi since version 2.

## [3.0.14] - 2022-03-22
- Feat: added Azure login
- Fix: admininfo actions can now start with "\n"

## [3.0.13] - 2022-03-14

- Fix: submodule vi working again
Expand Down
2 changes: 1 addition & 1 deletion vi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

vi_conf = {
# Vi version number
"vi.version": (3, 0, 13),
"vi.version": (3, 0, 14),
# ViUR server version number
"core.version": None,
"core.version.min": (3, 0, 0), # minimal core Version
Expand Down
33 changes: 33 additions & 0 deletions vi/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,39 @@ def canHandle(method, secondFactor):
loginHandlerSelector.insert(0, GoogleAccountLoginHandler.canHandle, GoogleAccountLoginHandler)


class OAuthAccountLoginHandler(BaseLoginHandler):
cssname = "oauthaccount"

def __init__(self, loginScreen, *args, **kwargs):
super(OAuthAccountLoginHandler, self).__init__(loginScreen, *args, **kwargs)

self.loginBtn = Button(translate("Login with OAuth"), callback=self.onLoginClick)
self.loginBtn.addClass("vi-login-btn btn--viur")
self.mask.appendChild(self.loginBtn)

def onLoginClick(self, sender = None):
self.lock()

NetworkService.request( None, "/vi/skey", successHandler=self.doSkeySuccess)

def doSkeySuccess( self, req ):
skey = self.parseAnswer(req)
#language=HTML
self.appendChild("""
<form [name]="loginform" action="/vi/user/auth_oauth2/login" method="POST" style="display:none">
<input type="hidden" name="skey" value="{{skey}}">
</form>
""",
skey=skey
)
self.loginform.element.submit()

@staticmethod
def canHandle(method, secondFactor):
return method == "X-VIUR-AUTH-OAuth2"

loginHandlerSelector.insert(0, OAuthAccountLoginHandler.canHandle, OAuthAccountLoginHandler)

class LoginScreen(Screen):

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions vi/translations/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@
"one time password": "OTP-Token",
"verify": "Authentifizieren",
"vi.login.handler.googleaccount": "Google",
"vi.login.handler.oauthaccount": "Azure",
"login with google": "Mit Google einloggen",
"login with OAuth": "Mit Azure einloggen",

"ViUR-core (v{{core.version}}) is incompatible to this Vi (v{{vi.version}}). The ViUR-core version musst be greater or equal version v{{core.version.min}} and lower than v{{core.version.max}}.":
u"Die Version des verwendeten ViUR-core (v{{core.version}}) ist inkompatibel mit diesem Vi (v{{vi.version}}). Die Version des ViUR-core muss größer oder gleich Version v{{core.version.min}} und kleiner als v{{core.version.max}} sein.",
Expand Down
1 change: 1 addition & 0 deletions vi/translations/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"one time password": u"One Time Password",
"verify": u"Verify",
"vi.login.handler.googleaccount": u"Google",
"vi.login.handler.oauthaccount": "Azure",
"login with google": u"Login with Google",
"vi.login.insufficient-rights": u"Your current user has insufficient access rights to use "
u"this part of the software.\n\nPlease login under a different user.",
Expand Down

0 comments on commit 1249183

Please sign in to comment.