Debian Codegraph @

github/orgs_credential_authorizations.go

raw
1 // Copyright 2023 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 )
13
14 // CredentialAuthorization represents a credential authorized through SAML SSO.
15 type CredentialAuthorization struct {
16 // User login that owns the underlying credential.
17 Login *string `json:"login,omitempty"`
18
19 // Unique identifier for the credential.
20 CredentialID *int64 `json:"credential_id,omitempty"`
21
22 // Human-readable description of the credential type.
23 CredentialType *string `json:"credential_type,omitempty"`
24
25 // Last eight characters of the credential.
26 // Only included in responses with credential_type of personal access token.
27 TokenLastEight *string `json:"token_last_eight,omitempty"`
28
29 // Date when the credential was authorized for use.
30 CredentialAuthorizedAt *Timestamp `json:"credential_authorized_at,omitempty"`
31
32 // Date when the credential was last accessed.
33 // May be null if it was never accessed.
34 CredentialAccessedAt *Timestamp `json:"credential_accessed_at,omitempty"`
35
36 // List of oauth scopes the token has been granted.
37 Scopes []string `json:"scopes,omitempty"`
38
39 // Unique string to distinguish the credential.
40 // Only included in responses with credential_type of SSH Key.
41 Fingerprint *string `json:"fingerprint,omitempty"`
42
43 AuthorizedCredentialID *int64 `json:"authorized_credential_id,omitempty"`
44
45 // The title given to the ssh key.
46 // This will only be present when the credential is an ssh key.
47 AuthorizedCredentialTitle *string `json:"authorized_credential_title,omitempty"`
48
49 // The note given to the token.
50 // This will only be present when the credential is a token.
51 AuthorizedCredentialNote *string `json:"authorized_credential_note,omitempty"`
52
53 // The expiry for the token.
54 // This will only be present when the credential is a token.
55 AuthorizedCredentialExpiresAt *Timestamp `json:"authorized_credential_expires_at,omitempty"`
56 }
57
58 // ListCredentialAuthorizations lists credentials authorized through SAML SSO
59 // for a given organization. Only available with GitHub Enterprise Cloud.
60 //
61 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#list-saml-sso-authorizations-for-an-organization
62 //
63 //meta:operation GET /orgs/{org}/credential-authorizations
64 func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context, org string, opts *ListOptions) ([]*CredentialAuthorization, *Response, error) {
65 u := fmt.Sprintf("orgs/%v/credential-authorizations", org)
66 u, err := addOptions(u, opts)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 req, err := s.client.NewRequest(http.MethodGet, u, nil)
72 if err != nil {
73 return nil, nil, err
74 }
75
76 var creds []*CredentialAuthorization
77 resp, err := s.client.Do(ctx, req, &creds)
78 if err != nil {
79 return nil, resp, err
80 }
81
82 return creds, resp, nil
83 }
84
85 // RemoveCredentialAuthorization revokes the SAML SSO authorization for a given
86 // credential within an organization. Only available with GitHub Enterprise Cloud.
87 //
88 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#remove-a-saml-sso-authorization-for-an-organization
89 //
90 //meta:operation DELETE /orgs/{org}/credential-authorizations/{credential_id}
91 func (s *OrganizationsService) RemoveCredentialAuthorization(ctx context.Context, org string, credentialID int64) (*Response, error) {
92 u := fmt.Sprintf("orgs/%v/credential-authorizations/%v", org, credentialID)
93 req, err := s.client.NewRequest(http.MethodDelete, u, nil)
94 if err != nil {
95 return nil, err
96 }
97
98 return s.client.Do(ctx, req, nil)
99 }