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