...

Source file src/github.com/google/go-github/v55/github/orgs_credential_authorizations.go

Documentation: github.com/google/go-github/v55/github

     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/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-saml-sso-authorizations-for-an-organization
    62  func (s *OrganizationsService) ListCredentialAuthorizations(ctx context.Context, org string, opts *ListOptions) ([]*CredentialAuthorization, *Response, error) {
    63  	u := fmt.Sprintf("orgs/%v/credential-authorizations", org)
    64  	u, err := addOptions(u, opts)
    65  	if err != nil {
    66  		return nil, nil, err
    67  	}
    68  
    69  	req, err := s.client.NewRequest(http.MethodGet, u, nil)
    70  	if err != nil {
    71  		return nil, nil, err
    72  	}
    73  
    74  	var creds []*CredentialAuthorization
    75  	resp, err := s.client.Do(ctx, req, &creds)
    76  	if err != nil {
    77  		return nil, resp, err
    78  	}
    79  
    80  	return creds, resp, nil
    81  }
    82  
    83  // RemoveCredentialAuthorization revokes the SAML SSO authorization for a given
    84  // credential within an organization. Only available with GitHub Enterprise Cloud.
    85  //
    86  // 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
    87  func (s *OrganizationsService) RemoveCredentialAuthorization(ctx context.Context, org string, credentialID int64) (*Response, error) {
    88  	u := fmt.Sprintf("orgs/%v/credential-authorizations/%v", org, credentialID)
    89  	req, err := s.client.NewRequest(http.MethodDelete, u, nil)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  
    94  	return s.client.Do(ctx, req, nil)
    95  }
    96  

View as plain text