Casbin Forum runs on Casnode, the open-source Discourse-style forum. Try the Casnode demo →
Casbin Forum

When I directly call the Casdoor API, everything works perfectly.
(Here, the SECRET and RECOVERY_CODES are obtained from the /api/mfa/setup/initiate endpoint.)

curl --location --request POST 'http://localhost:8000/api/mfa/setup/enable?mfaType=app&owner=appscode&secret=SECRET&dest=null&recoveryCodes=RECOVERY_CODES&name=NAME' \
--header 'accept: application/json' \
--header 'Authorization: Bearer {{token}}' \
--header 'Cookie: casdoor_session_id=SESSION_ID'

However, I’m encountering an issue when trying to perform the same action using the Go SDK.

Problem Details

In the Go SDK code, the Enable function does not accept recoveryCodes as a parameter.
As a result, when I invoke it, I receive the following response:

Response:

{
    "error": "Failed to enable MFA: recovery codes is missing"
}

SDK Code Snippet

func (c *Client) Enable(owner, mfaType, name, secret string) (*MfaVerifyResponse, error) {
     mfaReq := MfaRequest{
          Owner:   owner,
          MfaType: mfaType,
          Name:    name,
          Secret:  secret,
     }

     postBytes, err := json.Marshal(mfaReq)
     if err != nil {
          return nil, err
     }

     resp, err := c.DoPost("mfa/setup/enable", nil, postBytes, true, false)
     if err != nil {
          return nil, err
     }

     dataBytes, err := json.Marshal(resp.Data)
     if err != nil {
          return nil, err
     }

     var mfaResp MfaVerifyResponse
     err = json.Unmarshal(dataBytes, &mfaResp)
     if err != nil {
          return nil, err
     }

     return &mfaResp, nil
}

Am I missing something. TA

https://github.com/casdoor/casdoor-go-sdk/issues/180

2views
2users
1 minread
1 / 2
Oct 2025