Created
January 7, 2018 14:10
-
-
Save kukat/49f2a53b6d74140fc28d2ef8fb6f44ae to your computer and use it in GitHub Desktop.
Client Initiated Account Linking
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
$.getScript('https://rawgit.com/auth0/jwt-decode/master/build/jwt-decode.js') | |
$.getScript('https://rawgit.com/emn178/js-sha256/master/build/sha256.min.js') | |
var realm = 'b2a' | |
var provider = 'facebook' | |
var auth = JSON.parse(window.sessionStorage.getItem(window.sessionStorage.key(0))) | |
var token = jwt_decode(auth.access_token) | |
var session = token.session_state | |
var client_id = token.aud | |
var nonce = Date.now() | |
var input = '' + nonce + session + client_id + provider | |
var inputArrayBuffer = new TextEncoder('utf-8').encode(input) | |
var check = sha256.array(inputArrayBuffer) | |
var test = String.fromCharCode.apply(null, new Uint8Array(check)) | |
var base64string = window.btoa(test) | |
var hash = base64string.replace(/\+/g, '-').replace(/\//g, '_') | |
var redirect_uri = window.location.href | |
var url = `http://localhost:8080/auth/realms/${realm}/broker/${provider}/link?client_id=${client_id}&redirect_uri=${redirect_uri}&nonce=${nonce}&hash=${hash}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment