139{
140 size_t inBytes, outBytes;
141 const char *dot;
142 char *key, *outData, inData[1024];
143
144
145
146 if (!strncmp(b64data, "Bearer%20", 9)) b64data += 9;
147
148
149
150
151
152 if (!(dot = index(b64data, '.'))) return false;
153
154
155
156
157 inBytes = dot - b64data;
158 if (inBytes >= (int)sizeof(inData)) return false;
159 memcpy(inData, b64data, inBytes);
160 inData[inBytes] = 0;
161
162
163
164 outBytes = DecodeBytesNeeded(inBytes);
165 outData = (char *)alloca(outBytes);
166
167
168
169 if (DecodeUrl(inData, inBytes, outData, outBytes)) return false;
170
171
172
173
174 if (outBytes <= 0 || *outData != '{' || outData[outBytes-1] != '}')
175 return false;
176
177
178
179 if (!(key = strstr(outData, "\"typ\""))) return false;
180
181
182
183 key += 5;
184 while(*key == ' ') key++;
185 if (*key != ':') return false;
186
187
188
189 key++;
190 while(*key == ' ') key++;
191 return strncmp(key, "\"JWT\"", 5) == 0;
192}