11import { KEYUTIL } from 'jsrsasign' ;
22import log from 'loglevel' ;
33import clipboard from 'clipboard-polyfill' ;
4+ import { isToken } from './editor/jwt.js' ;
45
56export function httpGet ( url , cache = true ) {
67 return new Promise ( ( resolve , reject ) => {
@@ -117,6 +118,25 @@ export function copyTokenLink(token, publicKeyOptional) {
117118 return url ;
118119}
119120
121+ function regexp ( body , flag ) {
122+ return new RegExp ( "[?&#]" + body + "(?:=([^&#]*)|&|#|$)" , flag ) ;
123+ }
124+
125+ const tokenRegexp = regexp ( '((?:id_|access_)?token|value)' , 'g' ) ;
126+
127+ export function getTokensFromLocation ( ) {
128+ const { href } = window . location ;
129+ let name , value ;
130+ const val = { } ;
131+
132+ try {
133+ while ( [ , name , value ] = tokenRegexp . exec ( href ) ) {
134+ if ( isToken ( value ) ) val [ name ] = value ;
135+ }
136+ } catch ( err ) { }
137+ return val ;
138+ }
139+
120140// https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
121141export function getParameterByName ( name , url ) {
122142 if ( ! url ) {
@@ -125,16 +145,16 @@ export function getParameterByName(name, url) {
125145
126146 name = name . replace ( / [ \[ \] ] / g, "\\$&" ) ;
127147
128- const regex = new RegExp ( "[?&]" + name + "(=([^&#]*)|&|#|$)" ) ;
148+ const regex = regexp ( name ) ;
129149 const results = regex . exec ( url ) ;
130150 if ( ! results ) {
131151 return null ;
132152 }
133- if ( ! results [ 2 ] ) {
153+ if ( ! results [ 1 ] ) {
134154 return '' ;
135155 }
136156
137- return decodeURIComponent ( results [ 2 ] . replace ( / \+ / g, " " ) ) ;
157+ return decodeURIComponent ( results [ 1 ] . replace ( / \+ / g, " " ) ) ;
138158}
139159
140160export function isWideScreen ( ) {
0 commit comments