xref: /haiku/src/apps/haikudepot/server/JwtTokenHelper.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
1 /*
2  * Copyright 2023, Andrew Lindesay <apl@lindesay.co.nz>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef JWT_TOKEN_HELPER_H
6 #define JWT_TOKEN_HELPER_H
7 
8 
9 #include <String.h>
10 
11 
12 class BMessage;
13 
14 
15 /*! The term "JWT" is short for "Java Web Token" and is a token format typically used to convey
16     proof of an authentication. The token is structured and contains three parts separated by the
17     full-stop character ".". The first part is a header, the middle part contains some data (which
18     is termed the "claims") and the last part is a signature proving the authenticity of the claims.
19 
20     The claims are base-64 encoded JSON and the JSON data typically conveys some key-value pairs
21     with a number of the key names being well-known through standards.
22 
23     This class contains a number of helper methods for working with JWT tokens.
24  */
25 
26  class JwtTokenHelper {
27  public:
28  	static	bool				IsValid(const BString& value);
29 
30  	static	status_t			ParseClaims(const BString& token,
31  									BMessage& message);
32 
33  private:
34  	static	bool				_IsBase64(char ch);
35  };
36 
37  #endif // JWT_TOKEN_HELPER_H
38