-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for SAML SSO authorization APIs #2835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gmlewis
merged 4 commits into
google:master
from
joaopenteado:credential-authorizations
Jul 24, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d4b4192
Added support for SAML SSO authorization APIs
joaopenteado cfba85a
Applied suggestions from code review
joaopenteado 756d7b4
Added `omitempty` to `CredentialAuthorization` struct members
joaopenteado 529eb79
Added tests for `ListOptions` in `ListCredentialAuthorizations`
joaopenteado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2023 The go-github AUTHORS. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// CredentialAuthorization represents a credential authorized through SAML SSO. | ||
type CredentialAuthorization struct { | ||
// User login that owns the underlying credential. | ||
Login *string `json:"login,omitempty"` | ||
|
||
// Unique identifier for the credential. | ||
CredentialID *int64 `json:"credential_id,omitempty"` | ||
|
||
// Human-readable description of the credential type. | ||
CredentialType *string `json:"credential_type,omitempty"` | ||
|
||
// Last eight characters of the credential. | ||
// Only included in responses with credential_type of personal access token. | ||
TokenLastEight *string `json:"token_last_eight,omitempty"` | ||
|
||
// Date when the credential was authorized for use. | ||
CredentialAuthorizedAt *Timestamp `json:"credential_authorized_at,omitempty"` | ||
|
||
// Date when the credential was last accessed. | ||
// May be null if it was never accessed. | ||
CredentialAccessedAt *Timestamp `json:"credential_accessed_at,omitempty"` | ||
|
||
// List of oauth scopes the token has been granted. | ||
Scopes []string `json:"scopes,omitempty"` | ||
|
||
// Unique string to distinguish the credential. | ||
// Only included in responses with credential_type of SSH Key. | ||
Fingerprint *string `json:"fingerprint,omitempty"` | ||
|
||
AuthorizedCredentialID *int64 `json:"authorized_credential_id,omitempty"` | ||
|
||
// The title given to the ssh key. | ||
// This will only be present when the credential is an ssh key. | ||
AuthorizedCredentialTitle *string `json:"authorized_credential_title,omitempty"` | ||
|
||
// The note given to the token. | ||
// This will only be present when the credential is a token. | ||
AuthorizedCredentialNote *string `json:"authorized_credential_note,omitempty"` | ||
|
||
// The expiry for the token. | ||
// This will only be present when the credential is a token. | ||
AuthorizedCredentialExpiresAt *Timestamp `json:"authorized_credential_expires_at,omitempty"` | ||
} | ||
|
||
// ListCredentialAuthorizations lists credentials authorized through SAML SSO | ||
// for a given organization. Only available with GitHub Enterprise Cloud. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization | ||
func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context, org string, opts *ListOptions) ([]*CredentialAuthorization, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/credential-authorizations", org) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest(http.MethodGet, u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var creds []*CredentialAuthorization | ||
resp, err := s.client.Do(ctx, req, &creds) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return creds, resp, nil | ||
} | ||
|
||
// RemoveCredentialAuthorization revokes the SAML SSO authorization for a given | ||
// credential within an organization. Only available with GitHub Enterprise Cloud. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#remove-a-saml-sso-authorization-for-an-organization | ||
func (s *OrganizationsService) RemoveCredentialAuthorization(ctx context.Context, org string, credentialID int64) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/credential-authorizations/%v", org, credentialID) | ||
req, err := s.client.NewRequest(http.MethodDelete, u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.