Hi. I / We had to learn about breaking change intr...
# talk-hydra
d
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
Hello Andreas, thanks for reporting this, that should not have happened. I will let the team know 🙏
b
@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
@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
@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
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
@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
@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
Yea it took a while to get it going, but we will have Hydra available in Ory Cloud soon 🙏
d
b
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
http.StatusGone
b
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
https://pkg.go.dev/net/http#pkg-constants HTTP status code 410 is StatusGone
b
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
I’ll answer in a bit
err.Model().(client.RequestWasHandledResponse) try this
b
Model()
does not exist. Maybe I have to first cast "error" interface into something?
Like a GenericError or JsonError hmmm
d
err.(*client.GenericOpenAPIError)
Copy code
err.(*client.GenericOpenAPIError).Model().(client.RequestWasHandledResponse)
Jesus
b
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
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
ok, will save some lines ^^
d
b
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
I think that I’ll update it soon. at least for Go
b
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
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
No worries. Feel free to ask Go related questions 🙂
b
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 )