https://www.ory.sh/ logo
#talk-hydra
Title
# talk-hydra
d

dry-book-88542

03/29/2022, 1:20 PM
Hi. I / We had to learn about breaking change introduced in auto-generated clients the hard way. I've created an issue about this: https://github.com/ory/hydra-client-ruby/issues/2
m

magnificent-energy-493

03/29/2022, 1:23 PM
Hello Andreas, thanks for reporting this, that should not have happened. I will let the team know 🙏
b

bulky-holiday-60244

03/29/2022, 3:31 PM
@User in Golang I also see a lot of changes (which is fine if that's only due to OpenAPI... but I didn't find a mention of this). See the image for how it has changed. But even if I can almost find all the things I used in the past. Impossible to know how to do my switch cases, I'm unable to find constants/types like: • GetConsentRequestNotFound • GetConsentRequestGone • ... Do you know where they are?
d

damp-sunset-69236

03/29/2022, 3:50 PM
@bulky-holiday-60244 Hello. The documentation for Go SDK is not updated yet. Here’s a PR A new SDK returns object, httpResponse, error on every call You can do something like that for your case (the code is not tested)
Copy code
config := client.NewConfiguration()
config.Servers = []client.ServerConfiguration{
        {
                URL: "<https://hydra.localhost:4445>", // Admin API
        },
}
c := client.NewAPIClient(config)
consentReq := c.AdminApi.GetConsentRequest(context.Todo())
// change params
consentRequest, res, err := consentReq.Execute()
if err != nil { //Handle error}
switch res.StatusCode {
case http.StatusNotFound:
        // Handle
        // Equals to *hydra_admin.GetConsentRequestNotFound
case http.StatusGone:
        // Handle it
default:
}
b

bulky-holiday-60244

03/29/2022, 4:00 PM
@damp-sunset-69236 thank you, just saw in details on: https://github.com/ory/hydra-client-go/blob/v1.10.6/client/admin/get_consent_request_responses.go#L124 that those previous types where only valid due to status code only. So I will go with what you provided (using HTTP code constants directly). I would have preferred constants as before because it allows to know which "error codes" are possible. (reading the doc' is fine, but things change! and having the code linter telling something is no longer possible (or new) helps a lot)
m

magnificent-energy-493

03/29/2022, 4:07 PM
Sadly most of the quirks seem to be stemming from OpenAPI issues 😞 We are actually looking for someone to work on the upstream issues so the SDKs are more stable there, so if you know someone who wants to work on open source fulltime, show them this ad: https://www.ory.sh/jobs/SDK-maintainer/
👍 1
b

bulky-holiday-60244

03/29/2022, 4:07 PM
@damp-sunset-69236 can I assume having "err != nil" means "httpResp != nil" ? as in your example? Also, previously I was able to do as on this image, to quickly get the payload. What is the trick now to leverage this? Without dealing with pure strings?
oh sorry! For this one I'm able to cast the answer... ^^
Copy code
hydra_admin.RequestWasHandledResponse
I think I got main things to fix my code... will have to modify it ^^(painful). I dream 2 years ago you had the Cloud offer haha... (even Kratos...). Did a lot with Hydra manually at that time
d

damp-sunset-69236

03/29/2022, 4:11 PM
@bulky-holiday-60244 Here’s tested example
Copy code
package main

import (
        "context"
        "fmt"
        "net/http"
        "os"

        client "<http://github.com/ory/hydra-client-go|github.com/ory/hydra-client-go>"
)

func main() {
        consentChallenge := "consentChallenge_example" // string |

        configuration := client.NewConfiguration()
        configuration.Servers = []client.ServerConfiguration{
                {
                        URL: "<http://localhost:4445>", // Admin API
                },
        }
        apiClient := client.NewAPIClient(configuration)
        resp, r, err := apiClient.AdminApi.GetConsentRequest(context.Background()).ConsentChallenge(consentChallenge).Execute()
        if err != nil {
                switch r.StatusCode {
                case http.StatusNotFound:
                        fmt.Println("Consent not found")
                case http.StatusGone:
                        fmt.Println("It's gone")
                default:
                        fmt.Fprintf(os.Stderr, "Error when calling `AdminApi.GetConsentRequest``: %v\n", err)
                        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
                }
        }
        // response from `GetConsentRequest`: ConsentRequest
        fmt.Fprintf(os.Stdout, "Response from `AdminApi.GetConsentRequest`: %v\n", resp)
}
m

magnificent-energy-493

03/29/2022, 4:11 PM
Yea it took a while to get it going, but we will have Hydra available in Ory Cloud soon 🙏
d

damp-sunset-69236

03/29/2022, 4:16 PM
b

bulky-holiday-60244

03/29/2022, 4:24 PM
Thank you both of you, will do this tomorrow 🙂 Have a good day!
I probably say "good" too fast. Just curious, which variable should I cast? I tried on "consentRequest/httpResponse/err" but I always get errors with the linter. I tried something like:
Copy code
errPayload, ok := httpResp.(*hydra_client.RequestWasHandledResponse)
d

damp-sunset-69236

03/29/2022, 4:35 PM
http.StatusGone
b

bulky-holiday-60244

03/29/2022, 4:35 PM
I did the switch with "http.StatusGone", but then I want to get the "redirectTo"
so I need to cast something into
RequestWasHandledResponse
, but which one ^^?
d

damp-sunset-69236

03/29/2022, 4:36 PM
https://pkg.go.dev/net/http#pkg-constants HTTP status code 410 is StatusGone
b

bulky-holiday-60244

03/29/2022, 4:36 PM
I know. Did you see the image of the documention? The "StatusGone" should provide a response payload named
RequestWasHandledResponse
.
I'm interested to get the content of
RequestWasHandledResponse
that embeds "RedirectTo", but I don't know from where I should get it since I'm not able to cast any of the three variable returned
message has been deleted
d

damp-sunset-69236

03/29/2022, 4:39 PM
I’ll answer in a bit
err.Model().(client.RequestWasHandledResponse) try this
b

bulky-holiday-60244

03/29/2022, 4:44 PM
Model()
does not exist. Maybe I have to first cast "error" interface into something?
Like a GenericError or JsonError hmmm
d

damp-sunset-69236

03/29/2022, 4:45 PM
err.(*client.GenericOpenAPIError)
Copy code
err.(*client.GenericOpenAPIError).Model().(client.RequestWasHandledResponse)
Jesus
b

bulky-holiday-60244

03/29/2022, 4:47 PM
Copy code
a, ok := err.(*hydra_client.GenericOpenAPIError)
			b, ok := a.Model().(*hydra_client.RequestWasHandledResponse)
indeed if I have to add proper checks on "ok" variables... the code gets loooong
d

damp-sunset-69236

03/29/2022, 4:50 PM
Copy code
switch r.StatusCode {
                case http.StatusNotFound:
                        notFound, ok := err.(*client.GenericOpenAPIError).Model().(client.JsonError)
                        fmt.Println(ok)
                        fmt.Println(*notFound.ErrorDescription)
....
According to the generated code you can follow this example because the type of err object is client.GenericOpenAPIError anyway and you can skip it
b

bulky-holiday-60244

03/29/2022, 4:52 PM
ok, will save some lines ^^
d

damp-sunset-69236

03/29/2022, 4:53 PM
b

bulky-holiday-60244

03/29/2022, 4:54 PM
yeah thank you for helping! The migration was not obvious to me ^^
maybe this could be posted on the Go package until the docs is properly updated? Or in an issue
d

damp-sunset-69236

03/29/2022, 4:56 PM
I think that I’ll update it soon. at least for Go
b

bulky-holiday-60244

03/29/2022, 4:57 PM
dealing with languages not typed would be a nightmare with OpenAPI v3, no ^^?
@damp-sunset-69236 do you have somewhere an example with the "AcceptConsentRequest"? Because for the "Reject" I was able to do as on the image. But to "Accept" I cannot find the method to set the "body" with all session parameters.
message has been deleted
Copy code
package main

import (
    "context"
    "fmt"
    "os"
    openapiclient "./openapi"
)

func main() {
    consentChallenge := "consentChallenge_example" // string | 
    rejectRequest := *openapiclient.NewRejectRequest() // RejectRequest |  (optional)

    configuration := openapiclient.NewConfiguration()
    apiClient := openapiclient.NewAPIClient(configuration)
    resp, r, err := apiClient.AdminApi.RejectConsentRequest(context.Background()).ConsentChallenge(consentChallenge).RejectRequest(rejectRequest).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `AdminApi.RejectConsentRequest``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `RejectConsentRequest`: CompletedRequest
    fmt.Fprintf(os.Stdout, "Response from `AdminApi.RejectConsentRequest`: %v\n", resp)
}
b

bulky-holiday-60244

03/29/2022, 5:23 PM
I'm terribly sorry, since it was the exact same naming, I thought it was a pointer to goes to the previous stage.
Copy code
AcceptConsentRequest(ctx).ConsentChallenge(challenge).AcceptConsentRequest(hydra_client.AcceptConsentRequest{
(contrary to
RejectConsentRequest(context.Background()).ConsentChallenge(consentChallenge).RejectRequest(rejectRequest
) Probably too tired to think about it, will stop wasting your time 🙂 Thanks again!
d

damp-sunset-69236

03/29/2022, 5:24 PM
No worries. Feel free to ask Go related questions 🙂
b

bulky-holiday-60244

03/29/2022, 5:38 PM
Why not haha! What's the structure you expect for the session tokens? The new one is a more complex map[string]:
Copy code
map[string]map[string]interface{}
I tried to look at
hydra_client.NewAcceptConsentRequest()
to see if there was an example but no. EDIT: please see last post on the channel, will make things clearer (sorry Andreas for spamming your thread :s )
3 Views