-
-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at OIDC Session management
- Loading branch information
Showing
11 changed files
with
271 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
} | ||
|
||
</style> | ||
{% block js %} | ||
{% endblock js %} | ||
</head> | ||
|
||
<body> | ||
|
61 changes: 61 additions & 0 deletions
61
oauth2_provider/templates/oauth2_provider/check_session_iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{% extends "oauth2_provider/base.html" %} | ||
|
||
{% block title %}Check Session IFrame{% endblock %} | ||
|
||
{% block js %} | ||
<script language="JavaScript" type="text/javascript"> | ||
async function sha256(message) { | ||
// Encode the message as UTF-8 | ||
const msgBuffer = new TextEncoder().encode(message); | ||
|
||
// Generate the hash | ||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); | ||
} | ||
|
||
window.addEventListener("message", receiveMessage); | ||
|
||
async function receiveMessage(e) { | ||
// e.data has client_id and session_state | ||
if (!e.data || typeof e.data != 'string' || e.data == 'error') { | ||
return; | ||
} | ||
|
||
try { | ||
const [clientId, sessionStateImage] = e.data.split(' '); | ||
const [sessionState, salt] = sessionStateImage.split('.'); | ||
|
||
const userAgentState = getUserAgentState(); | ||
|
||
const knownImage = await sha256(`${clientId} ${e.origin} ${userAgentState} ${salt}`); | ||
|
||
const currentState = `${knownImage}.${salt}`; | ||
|
||
const status = sessionState == currentState ? 'unchanged' : 'changed'; | ||
e.source.postMessage(status, e.origin); | ||
} catch(err) { | ||
e.source.postMessage('error', e.origin); | ||
} | ||
}; | ||
|
||
|
||
function getUserAgentState() { | ||
const cookieName = "{{ cookie_name }}"; | ||
|
||
if (document.cookie && document.cookie !== '') { | ||
const cookies = document.cookie.split(';'); | ||
for (var i = 0; i < cookies.length; i++) { | ||
const cookie = cookies[i].trim(); | ||
// Does this cookie string begin with the name we want? | ||
if (cookie.substring(0, cookieName.length + 1) === (cookieName + '=')) { | ||
return decodeURIComponent(cookie.substring(cookieName.length + 1)); | ||
} | ||
} | ||
} | ||
throw new Error('OIDC Session Cookie not set'); | ||
} | ||
</script> | ||
{% endblock %} | ||
|
||
{% block content %}OIDC Session Management OP Iframe{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.