Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
deb0cb8
Update out of date packages and remove the node-fiber dependency as i…
sqrrrl Apr 27, 2022
e8469f5
Adding Stack Overflow (#344)
May 2, 2022
133a068
Add pkce parameters in the authorization url (#366)
labnol May 16, 2022
42931f8
fix refresh token expiry lost during refresh
chrisirhc Apr 20, 2022
acf06e9
add failing test
chrisirhc Apr 20, 2022
0b21a3f
revert previous changes to go with a different approach
chrisirhc Apr 28, 2022
b72ebde
stab at expires at variables
chrisirhc Apr 28, 2022
27b2121
fix test and typo
chrisirhc Apr 28, 2022
56a83e9
fix typo
chrisirhc Apr 28, 2022
91a5132
clean up code for easier review, minimize changes, follow previus pat…
chrisirhc Apr 28, 2022
7adc577
add missing var
chrisirhc Apr 28, 2022
4c9eb09
fix canRefresh logic
chrisirhc May 17, 2022
678a576
add setExpiresAt tests
chrisirhc May 17, 2022
3d9d277
remove extra comment
chrisirhc May 17, 2022
5e2d216
add tests and fix typo in logic
chrisirhc May 17, 2022
8aa9abb
Tighten expire checks to differentiate between 0 and unset, rename fu…
sqrrrl May 17, 2022
673257d
Retain refresh token expiry on refreshing (#360)
chrisirhc May 17, 2022
f096691
Updated JSDoc syntax for better type suggestions - getRedirectUri (#…
sggolakiya Jun 17, 2022
36bd286
chore: Synced file(s) with googleworkspace/.github (#381)
googleworkspace-bot Jul 21, 2022
d265d07
Resolve merge conflicts
sqrrrl Aug 2, 2022
1e068ba
chore: Synced local '.github/workflows/automation.yml' with remote 's…
googleworkspace-bot Jul 21, 2022
9f93ac4
chore: Synced local '.github/workflows/automation.yml' with remote 's…
googleworkspace-bot Jul 22, 2022
76e4b16
chore: switch to main (#386)
jpoehnelt Jul 22, 2022
0960cb5
chore: Synced file(s) with googleworkspace/.github (#389)
googleworkspace-bot Jul 29, 2022
40bdb39
build: remove travis (#387)
jpoehnelt Aug 2, 2022
ee806d9
add failing test
chrisirhc Apr 20, 2022
d276f61
Resolve merge conflicts
sqrrrl Aug 2, 2022
b7268b7
Retain refresh token expiry on refreshing (#360)
chrisirhc May 17, 2022
c63dbf4
add failing test
chrisirhc Apr 20, 2022
9a9cd5f
Retain refresh token expiry on refreshing (#360)
chrisirhc May 17, 2022
120d7b1
fix: prevent samples from leaking OAuth client ID + Secret to users (…
AlnisS Jul 27, 2022
8bd2078
Add sample for Onshape (#377)
AlnisS Aug 2, 2022
94451ba
Retain refresh token expiry on refreshing (#360)
chrisirhc May 17, 2022
2060c61
Resolve merge conflicts
sqrrrl Aug 2, 2022
6ea08f3
Resolve conflicts (again)
sqrrrl Aug 2, 2022
7515e42
Retain refresh token expiry on refreshing (#360)
chrisirhc May 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
"extends": "google",
"parserOptions": {
Expand Down
17 changes: 17 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

.github/ @googleworkspace/workspace-devrel-dpe
39 changes: 39 additions & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# .github/sync-repo-settings.yaml
# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings for app options.
rebaseMergeAllowed: true
squashMergeAllowed: true
mergeCommitAllowed: false
deleteBranchOnMerge: true
branchProtectionRules:
- pattern: main
isAdminEnforced: false
requiresStrictStatusChecks: false
requiredStatusCheckContexts:
# .github/workflows/test.yml with a job called "test"
- "test"
# .github/workflows/lint.yml with a job called "lint"
- "lint"
# Google bots below
- "cla/google"
- "snippet-bot check"
- "header-check"
- "conventionalcommits.org"
requiredApprovingReviewCount: 1
requiresCodeOwnerReviews: true
permissionRules:
- team: workspace-devrel-dpe
permission: admin
69 changes: 69 additions & 0 deletions .github/workflows/automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: Automation
on: [push, pull_request, workflow_dispatch]
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}}
steps:
- name: approve
run: gh pr review --approve "$PR_URL"
- name: merge
run: gh pr merge --auto --squash --delete-branch "$PR_URL"
default-branch-migration:
# this job helps with migrating the default branch to main
# it pushes main to master if master exists and main is the default branch
# it pushes master to main if master is the default branch
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
# required otherwise GitHub blocks infinite loops in pushes originating in an action
token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }}
- name: Set env
run: |
# set DEFAULT BRANCH
echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')" >> $GITHUB_ENV;

# set HAS_MASTER_BRANCH
if [ ! -z "$(git ls-remote --heads origin master)" ]; then
echo "HAS_MASTER_BRANCH=true" >> $GITHUB_ENV
else
echo "HAS_MASTER_BRANCH=false" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: configure git
run: |
git config --global user.name 'googleworkspace-bot'
git config --global user.email 'googleworkspace-bot@google.com'
- if: ${{ env.DEFAULT_BRANCH == 'main' && env.HAS_MASTER_BRANCH == 'true' }}
name: Update master branch from main
run: |
git checkout -B master
git reset --hard origin/main
git push origin master
- if: ${{ env.DEFAULT_BRANCH == 'master'}}
name: Update main branch from master
run: |
git checkout -B main
git reset --hard origin/master
git push origin main
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
echo "No lint checks";
exit 1;
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
echo "No tests";
exit 1;
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# OAuth2 for Apps Script [![Build Status](https://travis-ci.org/googleworkspace/apps-script-oauth2.svg?branch=master)](https://travis-ci.org/googleworkspace/apps-script-oauth2)

OAuth2 for Apps Script is a library for Google Apps Script that provides the
ability to create and authorize OAuth2 tokens as well as refresh them when they
expire. This library uses Apps Script's
Expand Down Expand Up @@ -78,7 +76,7 @@ exact URL that the service will use when performing the OAuth flow:
* Logs the redirect URI to register.
*/
function logRedirectUri() {
var service = getService();
var service = getService_();
Logger.log(service.getRedirectUri());
}
```
Expand All @@ -95,8 +93,12 @@ information is not persisted to any data store, so you'll need to create this
object each time you want to use it. The example below shows how to create a
service for the Google Drive API.

Ensure the method is private (has an underscore at the end of the name) to
prevent clients from being able to call the method to read your client ID and
secret.

```js
function getDriveService() {
function getDriveService_() {
// Create a new service with the given name. The name will be used when
// persisting the authorized token, so ensure it is unique within the
// scope of the property store.
Expand Down Expand Up @@ -143,7 +145,7 @@ The URL is generated by the service, using the function `getAuthorizationUrl()`.

```js
function showSidebar() {
var driveService = getDriveService();
var driveService = getDriveService_();
if (!driveService.hasAccess()) {
var authorizationUrl = driveService.getAuthorizationUrl();
var template = HtmlService.createTemplate(
Expand All @@ -167,7 +169,7 @@ to the user.

```js
function authCallback(request) {
var driveService = getDriveService();
var driveService = getDriveService_();
var isAuthorized = driveService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
Expand All @@ -190,7 +192,7 @@ request in the "Authorization" header.

```js
function makeRequest() {
var driveService = getDriveService();
var driveService = getDriveService_();
var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files?maxResults=10', {
headers: {
Authorization: 'Bearer ' + driveService.getAccessToken()
Expand All @@ -208,7 +210,7 @@ different account, use the `reset()` method:

```js
function logout() {
var service = getDriveService()
var service = getDriveService_()
service.reset();
}
```
Expand Down Expand Up @@ -350,7 +352,7 @@ request parameters and saved saved into storage.

```js
function authCallback(request) {
var service = getService();
var service = getService_();
var authorized = service.handleCallback(request);
if (authorized) {
// Gets the authorized account ID from the scope string. Assumes the
Expand Down Expand Up @@ -401,7 +403,7 @@ optional hash of parameter names and values to the `getAuthorizationUrl()`
method:

```js
var authorizationUrl = getService().getAuthorizationUrl({
var authorizationUrl = getService_().getAuthorizationUrl({
// Pass the additional parameter "lang" with the value "fr".
lang: 'fr'
});
Expand Down Expand Up @@ -467,17 +469,17 @@ means selecting a service name that matches the API the user will authorize:

```js
function run() {
var gitHubService = getGitHubService();
var mediumService = getMediumService();
var gitHubService = getGitHubService_();
var mediumService = getMediumService_();
// ...
}

function getGitHubService() {
function getGitHubService_() {
return OAuth2.createService('GitHub')
// GitHub settings ...
}

function getMediumService() {
function getMediumService_() {
return OAuth2.createService('Medium')
// Medium settings ...
}
Expand All @@ -490,12 +492,12 @@ names:

```js
function run() {
var copyFromService = getGitHubService('from');
var copyToService = getGitHubService('to');
var copyFromService = getGitHubService_('from');
var copyToService = getGitHubService_('to');
// ...
}

function getGitHubService(label) {
function getGitHubService_(label) {
return OAuth2.createService('GitHub_' + label)
// GitHub settings ...
}
Expand Down
6 changes: 6 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Report a security issue

To report a security issue, please use https://g.co/vulnz. We use
https://g.co/vulnz for our intake, and do coordination and disclosure here on
GitHub (including using GitHub Security Advisory). The Google Security Team will
respond within 5 working days of your report on g.co/vulnz.
16 changes: 16 additions & 0 deletions docs/Service_.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<!DOCTYPE html>
<!--
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html lang="en">
<head>
<meta charset="utf-8">
Expand Down
16 changes: 16 additions & 0 deletions docs/Storage_.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<!DOCTYPE html>
<!--
Copyright 2022 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html lang="en">
<head>
<meta charset="utf-8">
Expand Down
Loading