Skip to content

Instantly share code, notes, and snippets.

@awa2
Created November 9, 2018 08:36
Show Gist options
  • Save awa2/0068a8ea2e9c9f37f7559f552f616782 to your computer and use it in GitHub Desktop.
Save awa2/0068a8ea2e9c9f37f7559f552f616782 to your computer and use it in GitHub Desktop.

Delegationとは

GSuiteは、そのドメイン全体を、サービスアカウントに対して委任することができる。 GSuite Admin Consoleから、委任するサービスアカウントを指定し、委任するスコープを設定できる

GSuite Become

このDelegationの仕組みを利用することで、指定されたスコープのユーザーのアクセストークンをサービスアカウントが取得することができる。

これは、ユーザーになりすます(Become)してアクセスされるため、プラバシーに配慮が必要。

const jwtClient = new google.auth.JWT({
  keyFile: path.join(__dirname, "credentials.json"),
  scopes: ['https://www.googleapis.com/auth/admin.directory.group.readonly'],
  subject: $EMAIL_ADDRESS
});

$EMAIL_ADDRESSの部分に、Becomeしたいユーザのメールアドレスを指定する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment