1
1
import { KEYUTIL } from 'jsrsasign' ;
2
2
import log from 'loglevel' ;
3
3
import clipboard from 'clipboard-polyfill' ;
4
+ import { isToken } from './editor/jwt.js' ;
4
5
5
6
export function httpGet ( url , cache = true ) {
6
7
return new Promise ( ( resolve , reject ) => {
@@ -117,6 +118,25 @@ export function copyTokenLink(token, publicKeyOptional) {
117
118
return url ;
118
119
}
119
120
121
+ function regexp ( body , flag ) {
122
+ return new RegExp ( "[?&#]" + body + "(?:=([^&#]*)|&|#|$)" , flag ) ;
123
+ }
124
+
125
+ const tokenRegexp = regexp ( '((?:id_|access_)?token)' , '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
+
120
140
// https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
121
141
export function getParameterByName ( name , url ) {
122
142
if ( ! url ) {
@@ -125,16 +145,16 @@ export function getParameterByName(name, url) {
125
145
126
146
name = name . replace ( / [ \[ \] ] / g, "\\$&" ) ;
127
147
128
- const regex = new RegExp ( "[?&]" + name + "(=([^&#]*)|&|#|$)" ) ;
148
+ const regex = regexp ( name ) ;
129
149
const results = regex . exec ( url ) ;
130
150
if ( ! results ) {
131
151
return null ;
132
152
}
133
- if ( ! results [ 2 ] ) {
153
+ if ( ! results [ 1 ] ) {
134
154
return '' ;
135
155
}
136
156
137
- return decodeURIComponent ( results [ 2 ] . replace ( / \+ / g, " " ) ) ;
157
+ return decodeURIComponent ( results [ 1 ] . replace ( / \+ / g, " " ) ) ;
138
158
}
139
159
140
160
export function isWideScreen ( ) {
0 commit comments