Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i18n_sso
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
i18n_sso
Merge requests
!8
Issue
#3417218
by Grimreaper: Enable Gitlab CI + Update README + Coding standards
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3417218
by Grimreaper: Enable Gitlab CI + Update README + Coding standards
issue/i18n_sso-3417218:3417218-enable-gitlab-ci
into
8.x-1.x
Overview
0
Commits
2
Pipelines
2
Changes
7
Merged
Florent Torregrosa
requested to merge
issue/i18n_sso-3417218:3417218-enable-gitlab-ci
into
8.x-1.x
1 year ago
Overview
0
Commits
2
Pipelines
2
Changes
7
Expand
Closes
#3417218
0
0
Merge request reports
Compare
8.x-1.x
version 1
e465ead9
1 year ago
8.x-1.x (base)
and
latest version
latest version
5075f642
2 commits,
1 year ago
version 1
e465ead9
1 commit,
1 year ago
7 files
+
140
−
72
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
js/i18n_sso.js
+
27
−
26
Options
@@ -5,12 +5,9 @@
* If so, it logs in user on current website and reload page.
*/
(
function
(
Drupal
,
drupalSettings
,
once
)
{
'
use strict
'
;
((
Drupal
,
drupalSettings
,
once
)
=>
{
Drupal
.
behaviors
.
i18n_sso
=
Drupal
.
behaviors
.
i18n_sso
||
{};
Drupal
.
behaviors
.
i18n_sso
.
attach
=
function
(
context
)
{
Drupal
.
behaviors
.
i18n_sso
.
attach
=
(
context
)
=>
{
Drupal
.
behaviors
.
i18n_sso
.
initLogin
(
context
);
};
@@ -23,31 +20,33 @@
* @param {HTMLDocument|HTMLElement} context
* An element to use as context for querySelectorAll.
*/
Drupal
.
behaviors
.
i18n_sso
.
initLogin
=
function
(
context
)
{
once
(
'
i18n_sso
'
,
drupalSettings
.
i18n_sso
.
wrapperSelector
,
context
).
forEach
(
function
(
element
)
{
var
div
=
document
.
createElement
(
'
div
'
);
div
.
setAttribute
(
'
id
'
,
'
sso-waiting
'
);
div
.
innerHTML
=
drupalSettings
.
i18n_sso
.
waiting
;
element
.
insertBefore
(
div
,
element
.
firstChild
);
Drupal
.
behaviors
.
i18n_sso
.
getToken
();
});
Drupal
.
behaviors
.
i18n_sso
.
initLogin
=
(
context
)
=>
{
once
(
'
i18n_sso
'
,
drupalSettings
.
i18n_sso
.
wrapperSelector
,
context
).
forEach
(
(
element
)
=>
{
const
div
=
document
.
createElement
(
'
div
'
);
div
.
setAttribute
(
'
id
'
,
'
sso-waiting
'
);
div
.
innerHTML
=
drupalSettings
.
i18n_sso
.
waiting
;
element
.
insertBefore
(
div
,
element
.
firstChild
);
Drupal
.
behaviors
.
i18n_sso
.
getToken
();
},
);
};
/**
* Retrieves token on configured url and calls the useToken function.
*/
Drupal
.
behaviors
.
i18n_sso
.
getToken
=
function
()
{
var
xhr
=
new
XMLHttpRequest
();
Drupal
.
behaviors
.
i18n_sso
.
getToken
=
()
=>
{
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'
POST
'
,
drupalSettings
.
i18n_sso
.
ssoUrl
);
xhr
.
withCredentials
=
true
;
xhr
.
setRequestHeader
(
'
Content-Type
'
,
'
application/x-www-form-urlencoded
'
);
xhr
.
onload
=
function
()
{
xhr
.
onload
=
()
=>
{
if
(
xhr
.
status
===
200
)
{
var
data
=
JSON
.
parse
(
xhr
.
responseText
);
const
data
=
JSON
.
parse
(
xhr
.
responseText
);
Drupal
.
behaviors
.
i18n_sso
.
useToken
(
data
);
}
};
xhr
.
send
(
'
origin=
'
+
encodeURIComponent
(
window
.
location
.
origin
));
xhr
.
send
(
`
origin=
${
encodeURIComponent
(
window
.
location
.
origin
)
}
`
);
};
/**
@@ -58,26 +57,28 @@
* @param {object} data
* The data retrieved from the SSO URL endpoint.
*/
Drupal
.
behaviors
.
i18n_sso
.
useToken
=
function
(
data
)
{
var
waitingElement
=
document
.
getElementById
(
'
sso-waiting
'
);
Drupal
.
behaviors
.
i18n_sso
.
useToken
=
(
data
)
=>
{
const
waitingElement
=
document
.
getElementById
(
'
sso-waiting
'
);
if
(
waitingElement
)
{
waitingElement
.
innerHTML
=
data
.
message
;
if
(
data
.
token
!==
false
)
{
var
xhr
=
new
XMLHttpRequest
();
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'
POST
'
,
drupalSettings
.
i18n_sso
.
ssoLogin
);
xhr
.
setRequestHeader
(
'
Content-Type
'
,
'
application/x-www-form-urlencoded
'
);
xhr
.
onload
=
function
()
{
xhr
.
setRequestHeader
(
'
Content-Type
'
,
'
application/x-www-form-urlencoded
'
,
);
xhr
.
onload
=
()
=>
{
if
(
xhr
.
status
===
200
)
{
var
loginData
=
JSON
.
parse
(
xhr
.
responseText
);
const
loginData
=
JSON
.
parse
(
xhr
.
responseText
);
waitingElement
.
innerHTML
=
loginData
.
message
;
if
(
loginData
.
success
===
true
)
{
window
.
location
.
reload
();
}
}
};
xhr
.
send
(
'
token=
'
+
encodeURIComponent
(
data
.
token
));
xhr
.
send
(
`
token=
${
encodeURIComponent
(
data
.
token
)
}
`
);
}
}
};
})(
Drupal
,
drupalSettings
,
once
);
Loading