@@ -67,8 +67,8 @@ type OAuthConnectionType string
6767const (
6868 AppleOauth OAuthConnectionType = "AppleOauth"
6969 GithubOauth OAuthConnectionType = "GitHubOauth"
70- GoogleOAuth OAuthConnectionType = "GoogleOAuth "
71- MicrosoftOAuth OAuthConnectionType = "MicrosoftOAuth "
70+ GoogleOauth OAuthConnectionType = "GoogleOauth "
71+ MicrosoftOauth OAuthConnectionType = "MicrosoftOauth "
7272)
7373
7474// OAuthConnectionState represents the state of an OAuth Connection.
@@ -343,3 +343,41 @@ func (c *Client) UpdateOAuthCredential(ctx context.Context, opts UpdateOAuthCred
343343 err = dec .Decode (& body )
344344 return body , err
345345}
346+
347+ type CreateOAuthCredentialOpts struct {
348+ Type OAuthConnectionType `json:"type"`
349+ }
350+
351+ func (c * Client ) CreateOAuthCredential (ctx context.Context , opts CreateOAuthCredentialOpts ) (OAuthCredential , error ) {
352+ c .once .Do (c .init )
353+
354+ data , err := c .JSONEncode (opts )
355+ if err != nil {
356+ return OAuthCredential {}, err
357+ }
358+
359+ endpoint := fmt .Sprintf ("%s/oauth-credentials" , c .Endpoint )
360+ req , err := http .NewRequest (http .MethodPost , endpoint , bytes .NewBuffer (data ))
361+ if err != nil {
362+ return OAuthCredential {}, err
363+ }
364+ req = req .WithContext (ctx )
365+ req .Header .Set ("Content-Type" , "application/json" )
366+ req .Header .Set ("Authorization" , "Bearer " + c .APIKey )
367+ req .Header .Set ("User-Agent" , "workos-go/" + workos .Version )
368+
369+ res , err := c .HTTPClient .Do (req )
370+ if err != nil {
371+ return OAuthCredential {}, err
372+ }
373+ defer res .Body .Close ()
374+
375+ if err = workos_errors .TryGetHTTPError (res ); err != nil {
376+ return OAuthCredential {}, err
377+ }
378+
379+ var body OAuthCredential
380+ dec := json .NewDecoder (res .Body )
381+ err = dec .Decode (& body )
382+ return body , err
383+ }
0 commit comments