```_, _, err := client.OAuth2Api.CreateOAuth2Clien...
# ory-network
b
Copy code
_, _, err := client.OAuth2Api.CreateOAuth2Client(context.Background()).
		OAuth2Client(ory.OAuth2Client{
			ClientId:                pointer.ToString("clientId"),
			ClientName:              pointer.ToString("clientName"),
			ClientSecret:            pointer.ToString("clientSecret"),
			GrantTypes:              []string{"authorization_code", "refresh_token"},
			RedirectUris:            []string{"<https://www.ory.sh/>"},
			ResponseTypes:           []string{"code", "id_token"},
			Scope:                   pointer.ToString("openid offline"),
			TokenEndpointAuthMethod: pointer.ToString("client_secret_post"),
			Metadata:                nil,
		}).Execute()
Error:
Copy code
json: cannot unmarshal object into Go struct field ErrorOAuth2.error of type string
while creating oauthclient this is the error am getting
Copy code
var oryAuthedContext = context.WithValue(context.Background(), ory.ContextAccessToken, "ory_pat_ACe9oVHW")
when oryAuthedContext is used as context 400 Bad Request is the response
p
What is the response body of the 400 bad request? usually the response contains valuable information of the problem
b
Copy code
{
  "body": {
    "Reader": {}
  },
  "error": "400 Bad Request",
  "status": "400 Bad Request"
}
i printed the response body, error, and status
Copy code
func (h *Handler) CreateOauthClientHandler(c *gin.Context) {
	// metaData := map[string]interface{}{
	// 	"registration": os.Getenv("OAUTH_REGISTRATION"),
	// }

	// clientId := os.Getenv("CLIENT_ID")
	// clientSecret := os.Getenv("CLIENT_SECRET")
	// clientName := os.Getenv("CLIENT_NAME")
	// redirectUris := os.Getenv("REDIRECT_URIS")
	
	log.Println(h.ctx.Value(ory.ContextAccessToken))
	
		_, res, err := h.ApiClient.OAuth2Api.CreateOAuth2Client(h.ctx).
			OAuth2Client(ory.OAuth2Client{
				ClientId:                pointer.ToString("test-client"),
				ClientName:              pointer.ToString("auth-client-test"),
				ClientSecret:            pointer.ToString("secret"),
				GrantTypes:              []string{"authorization_code", "refresh_token"},
				RedirectUris:            []string{"<http://localhost:3000/callback>"},
				ResponseTypes:           []string{"code", "id_token"},
				Scope:                   pointer.ToString("openid offline"),
				TokenEndpointAuthMethod: pointer.ToString("client_secret_post"),
			}).Execute()
defer res.Body.Close()
		if err != nil {
			h.logger.Println(err.Error())
			c.JSON(500, gin.H{
				"error": err.Error(),
				"status": res.Status,
				"body": res.Body,
			})
			return
		}
		c.JSON(200, gin.H{
			"message": "Oauth2.0 client created successfully",
		})
	}
p
I would try first send a curl or postman request to the api directly first http://localhost:3000/docs/reference/api#tag/oAuth2/operation/createOAuth2Client that way you can know which fields you are missing. Not sure why it wouldn't give you an error body but it might not be decoding it correctly.
b
Copy code
&{400 Bad Request 400 HTTP/2.0 2 0 map[Alt-Svc:[h3=":443"; ma=86400, h3-29=":443"; ma=86400] Cache-Control:[private, no-cache, no-store, must-revalidate] Cf-Cache-Status:[DYNAMIC] Cf-Ray:[7876a8c85d119638-DEL] Content-Length:[201] Content-Type:[application/json] Date:[Tue, 10 Jan 2023 16:06:20 GMT] Server:[cloudflare] Set-Cookie:[__cflb=0pg1SGLfsntzdyWGAy13P2Jp3U9FyhvDwBgd6Jfu; SameSite=None; Secure; path=/; expires=Tue, 10-Jan-23 17:06:20 GMT; HttpOnly] Vary:[Origin]] {{"error":"The request was malformed or contained invalid parameters","error_description":"It is no longer possible to set an OAuth2 Client ID as a user. The system will generate a unique ID for you."}
} 201 [] false false map[] 0x14000570400 0x140001e4370}
p
So as the error indicates, the client id cannot be set. Remove the client id from the body
b
👍
so its not possible to create a static client id
p
No, it will generate it and return the id in the response
b
i thought of configuring the oauth client with client id , client secret before hand and create the oauth client in hydra with same client id and client secret