Extension:JWTAuth

The JWTAuth extension adds support for using JSON Web Tokens to log in to MediaWiki. JWTs are a common medium for conveying an authentication assertion in the tangible form of a token.

Prerequisites
JWTAuth is not a complete auth system. It is simply the last mile of processing JWTs. To learn more about how JWTs work, go to JWT.io. JWTAuth only facilitates the verification of JWTs that were already issued. Therefore, an auth system that issues JWTs is the primary prerequisite.

The JWT needs to be passed into the wiki's Special:JWTLogin page. It will take whatever content is ed in the   parameter (query string) and process it. The content should begin with  (with a space after the word "Bearer") or , followed by the actual JWT.

Comparison with PluggableAuth
JWTAuth is not intended to be a competitor to PluggableAuth. JWTAuth does not deal with the actual authentication against the user base. It only verifies JWTs given to it. Consequently, JWTAuth only deals with MediaWiki's SessionManager. Meanwhile, PluggableAuth deals with AuthManager.

Limitations
One inherent limitation of JWTAuth is its inability to check for whether tokens are revoked. This is not a bug; it is expected behavior because of the design of this auth process. It is able to detect whether the token is expired or forged, but if a token were to be revoked before the scheduled expiry time, the JWTAuth extension would have no way of knowing, as it doesn't talk back with the IdP who issued the token. Most PluggableAuth-based extensions don't suffer from this limitation. Usually, it's best to use the JWTAuth extension in an environment where the ability to immediate revoke a token is either unnecessary because another layer of auth would take care of it (like a company-issued computer shutting down when its associated employee's employment comes to an end), or not important. The best way to mitigate this issue would be to set the validity period to be as short as possible.

This also means JWTAuth doesn't include single sign-out.

There are many discussions of the merits of using JWTs versus other authentication mechanisms, and especially about what the best way to use them would be, but they are beyond the scope of this page. Please see JWT.io to learn more about JWTs.

Advantages
However, JWTAuth is relatively fast compared to using the authentication process defined by AuthManager and PluggableAuth because it does not involve any back-and-forth between the IdP and the SP. JWTs are useful for persisting auth session throughout the token's life because it means it can reuse token across multiple services and avoids needing to log in multiple times. It's best for systems where user will be logged in to several sites at once, including MediaWiki, and when sites are accessed from a central login system.

The JWTAuth extension doesn't require a JWT to be sent with each request to the web server. It only needs it to be sent once to Special:JWTLogin per login session. Once the JWTAuth extension authenticates the user based on the validity of the token, a cookie is set in MediaWiki to authenticate them for the rest of the MediaWiki session. The rest of the session is managed by MediaWiki and JWTAuth doesn't interface with it after that point.

Configuration

 * The algorithm used to encode and decode the JWT.
 * The algorithm used to encode and decode the JWT.


 * When using a symmetric algorithm, this is the shared passkey used to encode and decode the JWT.
 * When using an asymmetric algorithm, this is the public key. (The private key would be stored on side of the issuer of the JWT.)
 * When using an asymmetric algorithm, this is the public key. (The private key would be stored on side of the issuer of the JWT.)


 * The mapping of any custom group names passed in via the  claim.
 * The mapping of any custom group names passed in via the  claim.

Integrating your auth system with JWTAuth on MediaWiki
The following procedure must be followed to successfully authenticate a user into the wiki:


 * 1) A JWT claim must be well formed and encoded into the JWT payload format using the key that has already been agreed upon.
 * 2) Find the path to your wiki's location of  . For instance, if your wiki is under   and   then the location is.
 * 3) The payload must be  ed to this aforementioned URL. The URL should have a parameter called   with the content  . For instance,.
 * 4) The payload must conform to the claim names promulgated by IANA: https://www.iana.org/assignments/jwt/jwt.xhtml

Below are the claims that are required by the JWTAuth extension. If any of these are missing, the authentication process will fail. If you are unsure of what these mean, or the allowed values for them, please visit https://jwt.io for more details.


 * : Username. This is used by JWTAuth to form the user's username on MediaWiki. Please make sure the usernames conform to MediaWiki's allowed username rules.
 * : Expiry timestamp.
 * : Issued at timestamp.
 * : Not valid before timestamp.
 * : Issuer
 * : Audience
 * : Subject

You can put nonsense (but nonempty) values for,  , and  , as they are not checked by JWTAuth, but our JWT decoding library (Firebase JWT) will cause the auth process to fail if they are not set.

The following claims are optional, but are highly recommended because they will be added to users' profiles:



As of 0.1.0, most of these claim names cannot be changed to match the token generator's preferences because these claim names are standard conventions. The party generating the token is responsible for sending well-formed responses that conform to internet standards. The group claims name can be changed to match your preferences by modifying.

If you want to assign groups to a user, pass them in, separated by commas, by using the  claim. For instance,. Then, define the mapping in  like it was done in the example config shown above.

Please see the README for this extension for more details.