Skip to content

Commit 441b81f

Browse files
New oauth docs link & state option
- Updated the links to the now published oauth Modrinth docs - Added an option to add a - Added documentation for the GetTokenResponse
1 parent c8fb083 commit 441b81f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Modrinth.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,23 +485,25 @@ export default class Modrinth {
485485
*
486486
* (Rquest to `https://api.modrinth.com/_internal/oauth/token`)
487487
*
488-
* [Modrinth OAuth Guide](https://github.com/modrinth/code/pull/3342/files)
488+
* [Modrinth OAuth Guide](https://docs.modrinth.com/guide/oauth/)
489489
* @param code The authorization code gotten from the authorization URL
490490
* @param clientId The ID of the client
491491
* @param redirectUri The uri to redirect to after getting the token (must be listed in the client's redirect URIs)
492+
* @param authorization The authorization header to use (if not set, the one from the options will be used)
492493
* @returns The access token and other token information
493494
* @category Auth
494495
*/
495496
getToken(
496497
code: string,
497498
clientId: string,
498-
redirectUri: string
499+
redirectUri: string,
500+
authorization?: string
499501
): Promise<GetTokenResponse> {
500502
return new GetTokenRoute(
501503
this.getApiUrl(),
502504
this.options.userAgent,
503505
this.cacheManager,
504-
this.options.authorization,
506+
authorization || this.options.authorization,
505507
code,
506508
clientId,
507509
redirectUri
@@ -511,10 +513,11 @@ export default class Modrinth {
511513
/**
512514
* Generate an authorization URL to get an authorization code
513515
*
514-
* [Modrinth OAuth Guide](https://github.com/modrinth/code/pull/3342/files)
516+
* [Modrinth OAuth Guide](https://docs.modrinth.com/guide/oauth/)
515517
* @param clientId The ID of the client
516518
* @param redirectUri The uri to redirect to with the authorization code (must be listed in the client's redirect URIs)
517519
* @param scopes The scopes to request authorization for (must be listed in the client's scopes)
520+
* @param state An optional state parameter to include in the URL (useful for CSRF protection)
518521
* @returns The URL to get the authorization code
519522
* @category Auth
520523
*
@@ -528,12 +531,14 @@ export default class Modrinth {
528531
generateAuthorizationUrl(
529532
clientId: string,
530533
redirectUri: string,
531-
scopes: AuthScope[]
534+
scopes: AuthScope[],
535+
state?: string
532536
): string {
533537
const url = new URL('https://modrinth.com/auth/authorize');
534538
url.searchParams.append('client_id', clientId);
535539
url.searchParams.append('redirect_uri', redirectUri);
536540
url.searchParams.append('scope', scopes.join('+'));
541+
if (state) url.searchParams.append('state', state);
537542
return url.toString();
538543
}
539544
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export interface GetTokenResponse {
2+
/** The access token you can use to access the API */
23
access_token: string;
4+
/** Currently only `Bearer` */
35
token_type: string;
6+
/** The amount of seconds until the access token expires */
47
expires_in: number;
58
}

0 commit comments

Comments
 (0)