Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Call /oidc/logout/ before logging in to ensure there is no session left on taiga-back #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions front/coffee/oidc_auth.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module = angular.module('taigaContrib.oidcAuth', [])

OIDCLoginButtonDirective = ($window, $params, $location, $config, $events, $confirm, $auth, $navUrls, $loader, $rootScope) ->
OIDCLoginButtonDirective = ($window, $params, $location, $config, $events, $confirm, $auth, $navUrls, $loader, $rootScope, $tgHttp) ->
# Login or register a user with their OIDC account.

link = ($scope, $el, $attrs) ->
Expand Down Expand Up @@ -65,18 +65,21 @@ OIDCLoginButtonDirective = ($window, $params, $location, $config, $events, $conf
loginWithOIDCAccount()

$el.on "click", ".button-auth", (event) ->
if $params.next and $params.next != $navUrls.resolve("login")
nextUrl = $params.next
else
nextUrl = $navUrls.resolve("home")
base_url = $config.get("api", "/api/v1/").split('/').slice(0, -3).join("/")
url = urljoin(
base_url,
$config.get("oidcMountPoint", "/oidc"),
"authenticate/"
)
url += "?next=" + nextUrl
$window.location.href = url
$tgHttp.post("/oidc/logout/").then (r) ->
if $params.next and $params.next != $navUrls.resolve("login")
nextUrl = $params.next
else
nextUrl = $navUrls.resolve("home")
base_url = $config.get("api", "/api/v1/").split('/').slice(0, -3).join("/")
url = urljoin(
base_url,
$config.get("oidcMountPoint", "/oidc"),
"authenticate/"
)
url += "?next=" + nextUrl
$window.location.href = url
.catch (e) ->
console.error("failed logging out: #{ e }")

$scope.$on "$destroy", ->
$el.off()
Expand All @@ -93,5 +96,5 @@ OIDCLoginButtonDirective = ($window, $params, $location, $config, $events, $conf

module.directive("tgOidcLoginButton", [
"$window", '$routeParams', "$tgLocation", "$tgConfig", "$tgEvents",
"$tgConfirm", "$tgAuth", "$tgNavUrls", "tgLoader", "$rootScope",
"$tgConfirm", "$tgAuth", "$tgNavUrls", "tgLoader", "$rootScope", "$tgHttp",
OIDCLoginButtonDirective])