Creating your own auth provider for the API¶
Thank you for your interest in contributing to the GlobalTags API! Contributions are welcome and greatly appreciated.
Setting Up Your Development Environment¶
- Create a fork of the API repository
- Clone your fork of the Repository
-
Install Dependencies
Ensure you have bun installed. Then run:
bun i -
Create a config
-
Run the API
bun dev
Step-by-Step Guide¶
Info
The GlobalTags API uses an AuthProvider class to handle authentication. To extend the authentication mechanism, you can implement your own class by extending src/auth/AuthProvider.
Basic Information
As outlined in the How Authentication Works section, the Authorization header must consist of two values: id and token.
You need to define the following values:
id: The unique identifier for your provider. In this example, we'll useTestingas theid.-
name: A descriptive name for your service, such as the name of the authentication mechanism. In this example, we'll useMyServiceas thename. (1)- This
nameis used only for naming files and classes; it has no effect on the code itself.
- This
If you're unsure about the implementation, you can refer to the existing AuthProvider implementations for guidance.
1. Create a New AuthProvider Class¶
Create a new file in the src/auth/providers directory, for example, MyServiceProvider.ts, that extends AuthProvider. You need to implement the #getUUID method and initialize the constructor.
import AuthProvider from "../AuthProvider";
export default class MyServiceProvider extends AuthProvider {
constructor() {
super('Testing'); // (1)
}
async getUUID(token: string): Promise<string | null> { // (2)
return "00000000-0000-0000-0000-000000000000"; // (3)
}
}
- This is the
idvalue for your provider. - The
tokenparameter refers only to the token itself and does not include the authentication providerid. - Implement the logic to securely verify the token. This could involve an API request or verifying a JWT. Return
nullif the token does not map to a valid UUID.
2. Test Your Custom AuthProvider¶
To test your custom authentication provider, send a POST request to /players/<uuid> with the appropriate Authorization header in the format <id> <token>. For this example, a header could look like this:
Authorization: Testing somerandomtoken
Submitting Changes¶
You can then submit the changes by opening a pull request with a clear title and description of your changes.
License¶
By contributing to GlobalTags API, you agree that your contributions will be licensed under the MIT License.
Thank you for your contributions! Your efforts help improve the GlobalTags API for everyone.