Skip to content

Commit d425e9c

Browse files
authored
🤖 Merge PR DefinitelyTyped#74815 [google-apps-script-oauth2] Update types for version 43 by @sznorbert07
1 parent 4b728cf commit d425e9c

3 files changed

Lines changed: 102 additions & 3 deletions

File tree

‎types/google-apps-script-oauth2/google-apps-script-oauth2-tests.ts‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Examples from https://github.com/googlesamples/apps-script-oauth2
1+
// Examples from https://github.com/googleworkspace/apps-script-oauth2
22

33
/**
44
* Create the OAuth2 service.
@@ -17,6 +17,73 @@ function getDriveService() {
1717
.setParam("approval_prompt", "force");
1818
}
1919

20+
/**
21+
* Create sample service for Twitter.
22+
*/
23+
function getTwitterService() {
24+
const userProps = PropertiesService.getUserProperties();
25+
const clientId = "sampleClientId";
26+
const clientSecret = "sampleClientSecret";
27+
28+
return OAuth2.createService("Twitter")
29+
.setAuthorizationBaseUrl("https://twitter.com/i/oauth2/authorize")
30+
.setTokenUrl("https://api.twitter.com/2/oauth2/token")
31+
.setClientId(clientId)
32+
.setClientSecret(clientSecret)
33+
.setCallbackFunction("authCallback")
34+
.setPropertyStore(userProps)
35+
.setScope("users.read tweet.read offline.access")
36+
.generateCodeVerifier()
37+
.setTokenHeaders({
38+
"Authorization": "Basic " + Utilities.base64Encode(clientId + ":" + clientSecret),
39+
"Content-Type": "application/x-www-form-urlencoded",
40+
});
41+
}
42+
43+
/**
44+
* Create sample service with custom token method.
45+
*/
46+
function getTestClientWithCustomTokenMethod() {
47+
return OAuth2.createService("TestService")
48+
.setAuthorizationBaseUrl("https://example.com/auth")
49+
.setTokenUrl("https://example.com/token")
50+
.setClientId("sampleClientId")
51+
.setClientSecret("sampleClientSecret")
52+
.setCallbackFunction("authCallback")
53+
.setPropertyStore(PropertiesService.getUserProperties())
54+
.setTokenMethod("PUT");
55+
}
56+
57+
/**
58+
* Create sample service with code verifier and S256 code challenge method.
59+
*/
60+
function getTestClientWithAutoCodeVerifierAndS256ChallengeMethod() {
61+
return OAuth2.createService("TestService")
62+
.setAuthorizationBaseUrl("https://example.com/auth")
63+
.setTokenUrl("https://example.com/token")
64+
.setClientId("sampleClientId")
65+
.setClientSecret("sampleClientSecret")
66+
.setCallbackFunction("authCallback")
67+
.setPropertyStore(PropertiesService.getUserProperties())
68+
.generateCodeVerifier()
69+
.setCodeChallengeMethod(GoogleAppsScriptOAuth2.CodeChallengeMethod.S256);
70+
}
71+
72+
/**
73+
* Create sample service with code verifier and S256 code challenge method.
74+
*/
75+
function getTestClientWithManualCodeVerifierAndPlainChallengeMethod() {
76+
return OAuth2.createService("TestService")
77+
.setAuthorizationBaseUrl("https://example.com/auth")
78+
.setTokenUrl("https://example.com/token")
79+
.setClientId("sampleClientId")
80+
.setClientSecret("sampleClientSecret")
81+
.setCallbackFunction("authCallback")
82+
.setPropertyStore(PropertiesService.getUserProperties())
83+
.setCodeVerififer("sampleCodeVerifier")
84+
.setCodeChallengeMethod(GoogleAppsScriptOAuth2.CodeChallengeMethod.PLAIN);
85+
}
86+
2087
/**
2188
* Handle the callback.
2289
*/

‎types/google-apps-script-oauth2/index.d.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ declare namespace GoogleAppsScriptOAuth2 {
1717
* Often this URI needs to be entered into a configuration screen of your OAuth provider.
1818
*/
1919
getRedirectUri(scriptId?: string): string;
20+
/**
21+
* Gets the list of services with tokens stored in the given property store.
22+
* This is useful if you connect to the same API with multiple accounts and
23+
* need to keep track of them. If no stored tokens are found this will return
24+
* an empty array.
25+
*/
26+
getServiceNames(propertyStore: GoogleAppsScript.Properties.PropertiesService): string[];
2027
}
2128

2229
interface Storage {
@@ -217,6 +224,26 @@ declare namespace GoogleAppsScriptOAuth2 {
217224
* For Google services this URL should be `https://accounts.google.com/o/oauth2/token`.
218225
*/
219226
setTokenUrl(tokenUrl: string): OAuth2Service;
227+
/**
228+
* Sets the HTTP method to use when retrieving or refreshing the access token.
229+
* Default: `post`.
230+
*/
231+
setTokenMethod(tokenMethod: string): OAuth2Service;
232+
/**
233+
* Set the code verifier used for PKCE. For most use cases,
234+
* prefer `generateCodeVerifier` to automatically initialize the
235+
* value with a generated challenge string.
236+
*/
237+
setCodeVerififer(codeVerifier: string): OAuth2Service;
238+
/**
239+
* Sets the code verifier to a randomly generated challenge string.
240+
*/
241+
generateCodeVerifier(): OAuth2Service;
242+
/**
243+
* Set the code challenge method for PKCE. The default value method
244+
* when a code verifier is set is `S256`.
245+
*/
246+
setCodeChallengeMethod(method: CodeChallengeMethod): OAuth2Service;
220247
}
221248

222249
enum TokenFormat {
@@ -230,6 +257,11 @@ declare namespace GoogleAppsScriptOAuth2 {
230257
FORM_URL_ENCODED = "application/x-www-form-urlencoded",
231258
}
232259

260+
enum CodeChallengeMethod {
261+
S256 = "S256",
262+
PLAIN = "plain",
263+
}
264+
233265
interface TokenPayload {
234266
code: string;
235267
client_id: string;

‎types/google-apps-script-oauth2/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"private": true,
33
"name": "@types/google-apps-script-oauth2",
4-
"version": "38.0.9999",
4+
"version": "43.0.9999",
55
"nonNpm": true,
66
"nonNpmDescription": "google-apps-script-oauth2",
77
"projects": [
8-
"https://github.com/googlesamples/apps-script-oauth2"
8+
"https://github.com/googleworkspace/apps-script-oauth2"
99
],
1010
"dependencies": {
1111
"@types/google-apps-script": "*"

0 commit comments

Comments
 (0)