Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Send user information as JSON #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions back/taiga_contrib_oidc_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from json import dumps
from six.moves.urllib.parse import urlencode

from mozilla_django_oidc.views import OIDCAuthenticationCallbackView
Expand All @@ -28,20 +29,26 @@ def _make_login_url(data):
"front": {"domain": "localhost:9001", "scheme": "http", "name": "front"},
},
)

return "{}://{}/login?{}".format(
SITES["front"]["scheme"], SITES["front"]["domain"], urlencode(data)
)


class TaigaOIDCAuthenticationCallbackView(OIDCAuthenticationCallbackView):

@property
def success_url(self):
# Pull the next url from the session or settings--we don't need to
# sanitize here because it should already have been sanitized.
next_url = self.request.session.get("oidc_login_next") or "/"
data = make_auth_response_data(self.user)
data["type"] = "oidc"
data["next"] = next_url
user_data = make_auth_response_data(self.user)
user_data["roles"] = list(user_data["roles"])
user_data["date_joined"] = str(user_data["date_joined"])

data = {
"type": "oidc",
"data": dumps(user_data),
"next": self.request.session.get("oidc_login_next") or "/",
}

return _make_login_url(data)

@property
Expand All @@ -52,4 +59,5 @@ def failure_url(self):
"error": self.request.GET.get("error"),
"error_description": self.request.GET.get("error_description"),
}

return _make_login_url(data)
40 changes: 13 additions & 27 deletions front/coffee/oidc_auth.coffee
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
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, $rootScope) ->
# Login or register a user with their OIDC account.

link = ($scope, $el, $attrs) ->

loginSuccess = ->
# Login in the UI. Using $auth.login() is too GitHub-specific.
if $params.next and $params.next != $navUrls.resolve("login")
nextUrl = $params.next
else
nextUrl = $navUrls.resolve("home")

$events.setupConnection()

$auth.removeToken();
data = _.clone($params, false);
data = JSON.parse($params.data);

user = $auth.model.make_model("users", data);
$auth.setToken(user.auth_token);
$auth.setRefreshToken(user.refresh)
$auth.setUser(user);
$rootScope.$broadcast("auth:login", user)

# Cleanup the URL

$events.setupConnection() # I don't know why this is necessary.

scrub = (name, i) ->
$location.search(name, null)
[
'accepted_terms', 'auth_token', 'big_photo', 'bio', 'color', 'date_joined',
'email', 'full_name', 'full_name_display', 'gravatar_id', 'id', 'is_active',
'lang', 'max_memberships_private_projects', 'max_memberships_public_projects',
'max_private_projects', 'max_public_projects', 'next', 'photo', 'read_new_terms',
'roles', 'theme', 'timezone', 'total_private_projects', 'total_public_projects',
'type', 'username', 'uuid'
].forEach(scrub)

# Redirect to the destination page.

if $params.next and $params.next != $navUrls.resolve("login")
nextUrl = $params.next
else
nextUrl = $navUrls.resolve("home")

$location.path(nextUrl)
$window.location.href = nextUrl

loginError = ->
error_description = $params.error_description
Expand Down Expand Up @@ -93,5 +79,5 @@ OIDCLoginButtonDirective = ($window, $params, $location, $config, $events, $conf

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