@@ -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}
0 commit comments