Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GéoContrib
Géocontrib Frontend
Commits
0fbd316a
Commit
0fbd316a
authored
7 months ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
feat: add redirect to login page from api response
parent
0cb63206
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!822
REDMINE_ISSUE-18860 | Authentification GéoContrib via API OGS
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/store/index.js
+16
-7
16 additions, 7 deletions
src/store/index.js
with
16 additions
and
7 deletions
src/store/index.js
+
16
−
7
View file @
0fbd316a
...
...
@@ -183,14 +183,18 @@ export default new Vuex.Store({
});
}
},
/**
* Action to retrieve user information.
* - If a token is present in the URL, it indicates a Single Sign-On (SSO) attempt,
* in which case it logs out the user (if logged in) and connects via SSO with the token.
* Otherwise, it fetches user information from the Django API endpoint:
* - If no user is logged AND if the login should be done through SSO with a redirect,
* it naviguates to the login plateform, afterwards the user will be redirected with the token and the original url to open in geocontrib
* - Else it displays a message that the user is not logged but can still access the app as an anonymous user.
* - If a token is present in the URL, it indicates a Single Sign-On (SSO) attempt,
* in which case it logs out the user (if logged in) and connects via SSO with the token.
* - Otherwise, it fetches user information from the Django API endpoint:
* - If no user is logged in AND if the login should be done through SSO with a redirect,
* it navigates to the login platform. Afterward, the user will be redirected with the token and the original URL to open in Geocontrib.
* - Else if the response contains a login_url (to connect with OGS), the user is redirected to this url which will redirect the user
* to geocontrib after login, which will check again if the OGS session is activated
* - Otherwise, it displays a message that the user is not logged in but can still access the app as an anonymous user.
* A 'next' parameter is added to transfer to the OGS login page for redirection.
*/
async
GET_USER_INFO
({
state
,
commit
,
dispatch
})
{
// Extract token from URL query parameters
...
...
@@ -211,10 +215,12 @@ export default new Vuex.Store({
// Update the user state with received user data
if
(
response
&&
response
.
status
===
200
)
{
const
user
=
response
.
data
.
user
;
console
.
log
(
'
user
'
,
user
);
commit
(
'
SET_USER
'
,
user
);
}
})
.
catch
(()
=>
{
.
catch
((
error
)
=>
{
const
response
=
error
.
response
;
// If the instance is set to accept login with redirection
if
(
state
.
configuration
.
VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT
)
{
commit
(
'
DISPLAY_MESSAGE
'
,
{
...
...
@@ -222,6 +228,9 @@ export default new Vuex.Store({
});
// Call the SSO login plateform with url to redirect after login
window
.
open
(
`
${
state
.
configuration
.
VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT
}
/?url_redirect=
${
encodeURIComponent
(
currentUrl
)}
`
,
'
_self
'
);
}
else
if
(
response
&&
response
.
data
.
redirect
)
{
// If the backend return a login url, the user is redirected to connect through OGS login
window
.
location
.
href
=
response
.
data
.
login_url
;
}
else
{
// If the user is not logged in, display an info message
commit
(
'
DISPLAY_MESSAGE
'
,
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment