github.com/clerkinc/clerk-sdk-go@v1.49.1/clerk/saml_connections.go (about) 1 package clerk 2 3 import ( 4 "fmt" 5 "net/http" 6 ) 7 8 type SAMLConnectionsService service 9 10 type SAMLConnection struct { 11 ID string `json:"id"` 12 Object string `json:"object"` 13 Name string `json:"name"` 14 Domain string `json:"domain"` 15 IdpEntityID *string `json:"idp_entity_id"` 16 IdpSsoURL *string `json:"idp_sso_url"` 17 IdpCertificate *string `json:"idp_certificate"` 18 IdpMetadataURL *string `json:"idp_metadata_url"` 19 IdpMetadata *string `json:"idp_metadata"` 20 AcsURL string `json:"acs_url"` 21 SPEntityID string `json:"sp_entity_id"` 22 SPMetadataURL string `json:"sp_metadata_url"` 23 AttributeMapping SAMLConnectionAttributeMapping `json:"attribute_mapping"` 24 Active bool `json:"active"` 25 Provider string `json:"provider"` 26 UserCount int64 `json:"user_count"` 27 SyncUserAttributes bool `json:"sync_user_attributes"` 28 AllowSubdomains bool `json:"allow_subdomains"` 29 AllowIdpInitiated bool `json:"allow_idp_initiated"` 30 CreatedAt int64 `json:"created_at"` 31 UpdatedAt int64 `json:"updated_at"` 32 } 33 34 type SAMLConnectionAttributeMapping struct { 35 UserID string `json:"user_id"` 36 EmailAddress string `json:"email_address"` 37 FirstName string `json:"first_name"` 38 LastName string `json:"last_name"` 39 } 40 41 type ListSAMLConnectionsResponse struct { 42 Data []SAMLConnection `json:"data"` 43 TotalCount int64 `json:"total_count"` 44 } 45 46 type ListSAMLConnectionsParams struct { 47 Limit *int 48 Offset *int 49 Query *string 50 OrderBy *string 51 } 52 53 func (s SAMLConnectionsService) ListAll(params ListSAMLConnectionsParams) (*ListSAMLConnectionsResponse, error) { 54 req, err := s.client.NewRequest(http.MethodGet, SAMLConnectionsUrl) 55 if err != nil { 56 return nil, err 57 } 58 59 query := req.URL.Query() 60 addPaginationParams(query, PaginationParams{Limit: params.Limit, Offset: params.Offset}) 61 62 if params.Query != nil { 63 query.Set("query", *params.Query) 64 } 65 if params.OrderBy != nil { 66 query.Set("order_by", *params.OrderBy) 67 } 68 69 req.URL.RawQuery = query.Encode() 70 71 samlConnections := &ListSAMLConnectionsResponse{} 72 if _, err = s.client.Do(req, samlConnections); err != nil { 73 return nil, err 74 } 75 76 return samlConnections, nil 77 } 78 79 func (s SAMLConnectionsService) Read(id string) (*SAMLConnection, error) { 80 req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", SAMLConnectionsUrl, id)) 81 if err != nil { 82 return nil, err 83 } 84 85 samlConnection := &SAMLConnection{} 86 if _, err = s.client.Do(req, samlConnection); err != nil { 87 return nil, err 88 } 89 90 return samlConnection, nil 91 } 92 93 type CreateSAMLConnectionParams struct { 94 Name string `json:"name"` 95 Domain string `json:"domain"` 96 Provider string `json:"provider"` 97 IdpEntityID *string `json:"idp_entity_id,omitempty"` 98 IdpSsoURL *string `json:"idp_sso_url,omitempty"` 99 IdpCertificate *string `json:"idp_certificate,omitempty"` 100 IdpMetadataURL *string `json:"idp_metadata_url,omitempty"` 101 IdpMetadata *string `json:"idp_metadata,omitempty"` 102 AttributeMapping *SAMLConnectionAttributeMapping `json:"attribute_mapping,omitempty"` 103 } 104 105 func (s SAMLConnectionsService) Create(params *CreateSAMLConnectionParams) (*SAMLConnection, error) { 106 req, err := s.client.NewRequest(http.MethodPost, SAMLConnectionsUrl, params) 107 if err != nil { 108 return nil, err 109 } 110 111 resp := SAMLConnection{} 112 if _, err = s.client.Do(req, &resp); err != nil { 113 return nil, err 114 } 115 116 return &resp, nil 117 } 118 119 type UpdateSAMLConnectionParams struct { 120 Name *string `json:"name,omitempty"` 121 Domain *string `json:"domain,omitempty"` 122 IdpEntityID *string `json:"idp_entity_id,omitempty"` 123 IdpSsoURL *string `json:"idp_sso_url,omitempty"` 124 IdpCertificate *string `json:"idp_certificate,omitempty"` 125 IdpMetadataURL *string `json:"idp_metadata_url,omitempty"` 126 IdpMetadata *string `json:"idp_metadata,omitempty"` 127 AttributeMapping *SAMLConnectionAttributeMapping `json:"attribute_mapping,omitempty"` 128 Active *bool `json:"active,omitempty"` 129 SyncUserAttributes *bool `json:"sync_user_attributes,omitempty"` 130 AllowSubdomains *bool `json:"allow_subdomains,omitempty"` 131 AllowIdpInitiated *bool `json:"allow_idp_initiated,omitempty"` 132 } 133 134 func (s SAMLConnectionsService) Update(id string, params *UpdateSAMLConnectionParams) (*SAMLConnection, error) { 135 req, err := s.client.NewRequest(http.MethodPatch, fmt.Sprintf("%s/%s", SAMLConnectionsUrl, id), params) 136 if err != nil { 137 return nil, err 138 } 139 140 resp := SAMLConnection{} 141 if _, err = s.client.Do(req, &resp); err != nil { 142 return nil, err 143 } 144 145 return &resp, nil 146 } 147 148 func (s SAMLConnectionsService) Delete(id string) (*DeleteResponse, error) { 149 reqURL := fmt.Sprintf("%s/%s", SAMLConnectionsUrl, id) 150 req, err := s.client.NewRequest(http.MethodDelete, reqURL) 151 if err != nil { 152 return nil, err 153 } 154 155 resp := &DeleteResponse{} 156 if _, err = s.client.Do(req, resp); err != nil { 157 return nil, err 158 } 159 return resp, nil 160 }