Hello! I am wondering if that is possible automati...
# talk-hydra
g
Hello! I am wondering if that is possible automatically create pre-defined clients for Ory Hydra? We want OAuth2 clients to be created automatically for our dev environments when docker-compose is up. What would you recommend?
b
I have used self host hydra. That is possible with hydra admin client. I don't know if that is possible with cloud
g
@bright-policeman-41717 thank you! Yes, I found the import command. I am wondering if you were able to create oauth2-clients with the specific client ids. I see they deprecated the use of this field. But we need something like this for creating reproducible dev environments.
b
Hi, I used go sdk , to create oauth2 clients. Am not familiar with nodejs.
also you can refer this
<https://www.ory.sh/docs/reference/api>
if you are using cloud use can make a post request to this restapi and create a client
g
Thanks! I am using self-host, thinking to automate dev environment 🙂 I will take a look!
b
you can use the available sdk to create new clients with specific client id and client secret
Copy code
_, _, err = s.HydraAPIClient.AdminApi.CreateOAuth2Client(ctx).
				OAuth2Client(hydra.OAuth2Client{
					ClientId:                pointer.ToString(s.IDPConfig.ClientID),
					ClientName:              pointer.ToString("Test OAuth2 Client"),
					ClientSecret:            pointer.ToString(s.IDPConfig.ClientSecret),
					GrantTypes:              []string{"authorization_code", "refresh_token"},
					RedirectUris:            []string{fmt.Sprintf("<http://localhost:3001/login/generic_oauth>")},
					ResponseTypes:           []string{"code", "id_token"},
					Scope:                   pointer.ToString("openid offline"),
					TokenEndpointAuthMethod: pointer.ToString("client_secret_post"),
					Metadata:                s.IDPConfig.ClientMetadata,
				}).Execute()
			if err != nil {
				log.Fatalln("unable to create OAuth2 client: ", err)
			}
			<http://log.Info|log.Info>("Successfully created OAuth2 client!")
		}
this is in go to create a client