Skip to content

Commit 33f3af3

Browse files
feat: add usage instructions for organization parameter in SSO credential scripts (#101)
1 parent 033b888 commit 33f3af3

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
#!/bin/bash
22

3+
if [ -z "$1" ]; then
4+
echo "Usage: $0 <organization>"
5+
echo "Example: ./get-sso-enabled-pats.sh my-org"
6+
exit 1
7+
fi
8+
9+
org="$1"
10+
311
# more info:
412
# - https://github.blog/changelog/2019-04-09-credential-authorizations-api/
513
# - https://github.blog/changelog/2021-11-09-expiration-dates-of-saml-authorized-pats-available-via-api/
614
# - https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization
715

816
# gets all credential types ("personal access token", "SSH key", "OAuth app token", and "GitHub app token") and their expiration (if applicable)
917

10-
gh api --paginate /orgs/githubcustomers/credential-authorizations
18+
gh api --paginate /orgs/$org/credential-authorizations
1119

1220
# old - raw text output, 1 per line
13-
# gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type)"'
21+
# gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type)"'

gh-cli/get-sso-enabled-pats.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
#!/bin/bash
22

3+
if [ -z "$1" ]; then
4+
echo "Usage: $0 <organization>"
5+
echo "Example: ./get-sso-enabled-pats.sh my-org"
6+
exit 1
7+
fi
8+
9+
org="$1"
10+
311
# more info:
412
# - https://github.blog/changelog/2019-04-09-credential-authorizations-api/
513
# - https://github.blog/changelog/2021-11-09-expiration-dates-of-saml-authorized-pats-available-via-api/
614
# - https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization
715

816
# credential_type: personal access token, SSH key, OAuth app token, GitHub app token
9-
gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null)' # the null check is b/c we only want to get active PATs
17+
gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null)' # the null check is b/c we only want to get active PATs
1018

1119
# old - raw text output, 1 per line
12-
# gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null) | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type))"'
20+
# gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null) | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type))"'
1321

1422
# old - raw text output, 1 per line, with scopes
15-
# gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null) | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type) scopes: \((.scopes // ["None"]) | join(", "))"'
23+
# gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | select(.credential_type == "personal access token" and .token_last_eight != null) | "login: \(.login) expiration: \(.authorized_credential_expires_at) ID: \(.credential_id) note: \(.authorized_credential_note) type: \(.credential_type) scopes: \((.scopes // ["None"]) | join(", "))"'

gh-cli/get-sso-enabled-ssh-keys.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/bin/bash
22

3+
if [ -z "$1" ]; then
4+
echo "Usage: $0 <organization>"
5+
echo "Example: ./get-sso-enabled-pats.sh my-org"
6+
exit 1
7+
fi
8+
9+
org="$1"
10+
311
# more info:
412
# - https://github.blog/changelog/2019-04-09-credential-authorizations-api/
513
# - https://github.blog/changelog/2021-11-09-expiration-dates-of-saml-authorized-pats-available-via-api/
614
# - https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization
715

816
# credential_type: personal access token, SSH key, OAuth app token, GitHub app token
9-
gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | select(.credential_type == "SSH key")'
17+
gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | select(.credential_type == "SSH key")'
1018

1119
# old - raw text output, 1 per line
12-
# gh api --paginate /orgs/githubcustomers/credential-authorizations --jq='.[] | select(.credential_type == "SSH key") | "login: \(.login) ID: \(.credential_id) title: \(.authorized_credential_title) type: \(.credential_type)"'
20+
# gh api --paginate /orgs/$org/credential-authorizations --jq='.[] | select(.credential_type == "SSH key") | "login: \(.login) ID: \(.credential_id) title: \(.authorized_credential_title) type: \(.credential_type)"'

0 commit comments

Comments
 (0)