fusionauth / go-client Goto Github PK
View Code? Open in Web Editor NEWFusionAuth Go Client Library!
Home Page: https://fusionauth.io/
License: Apache License 2.0
FusionAuth Go Client Library!
Home Page: https://fusionauth.io/
License: Apache License 2.0
Hi, This is my golang code:
uuid := id2uuid(id)
fmt.Println(uuid)
userRequest := fusionauth.UserRequest{
SendSetPasswordEmail: false,
SkipVerification: true,
User: fusionauth.User{
SecureIdentity: fusionauth.SecureIdentity{
Password: "123456",
EncryptionScheme: "salted-md5",
},
Email: "[email protected]",
},
}
userReply, _, err := auth.CreateUser(uuid, userRequest)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", struct2JSON(userReply))
when I run this code, the result:
50166975-0100-0000-0516-796758492463
{"statusCode":400,"user":{}}
what's the problem?
I currently have my fusion auth client setup to use an APIKey. When calling the refresh token method as so
refreshResponse, errorList, err := fusionAuthClient.ExchangeRefreshTokenForJWT(fusionauth.RefreshRequest{
RefreshToken: refreshToken,
})
errorList
will contain an error stating I have not set the TenantID in the header. This is because the underlying method is calling StartAnonymous(...)
instead of Start(...)
. The current work around for me is to grab the configured tenant id and call the SetTenantId
method.
My expectation was for the method to work with the APIKey since I have it set on my fusionauth rest client.
Client.go
and FusionAuthClient.go
both declare same functions.
Installation log of go get github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:87:6: FusionAuthClient redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:52:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:100:28: (*FusionAuthClient).ActionUser redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:183:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:117:28: (*FusionAuthClient).AddUserToFamily redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:201:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:134:28: (*FusionAuthClient).CancelAction redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:219:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:152:28: (*FusionAuthClient).ChangePassword redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:238:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:170:28: (*FusionAuthClient).ChangePasswordByIdentity redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:257:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:185:28: (*FusionAuthClient).CommentOnUser redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:273:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:201:28: (*FusionAuthClient).CreateApplication redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:290:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:220:28: (*FusionAuthClient).CreateApplicationRole redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:310:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:240:28: (*FusionAuthClient).CreateAuditLog redeclared in this block
previous declaration at ../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/Client.go:331:6
../../go/src/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth/FusionAuthClient.go:240:28: too many errors
Hi, I fetch the access token and refresh token by the login api. I can use the refresh token to exchange the access token, but the refresh token must have the expire time, how can i update the refresh token?
I think the fusion api 'ExchangeRefreshTokenForJWT' which is used to exchange the access token by refresh token can return a new refresh token, but the slice in response is empty.
Or if the refresh token is expire, the user should login again?
For information purposes, here's a quick rundown of the things I've discovered and that I'll try to work on in the coming days. Please let me know if there's any related input from anyone's side.
CreateUser
as an example for many similar occurencies: the first parameter (userId
) is considered optional. If omitted, the FusionAuth API will create its own user ID. Yet, as is, this library does not support this optional behaviour.I'm gonna try to address these things and possibly others in upcoming PRs.
For example see the PatchUser method:
// PatchUser
// Updates, via PATCH, the user with the given Id.
// string userId The Id of the user to update.
// UserActionRequest request The request that contains just the new user action information.
func (c *FusionAuthClient) PatchUser(userId string, request map[string]interface{}) (*UserResponse, *Errors, error) {
According to the documentation, the second param is supposed to be a UserActionRequest (which is defined in Domain.go), but the method takes a map[string]interface{}
. I can work around it for now, but it seems there's a mix of methods that take specific request structs and others that take generic map[string]interface{}
I am using Fusioauth version 1.32.1, while using the change password by identity API, I am getting a 404 not found.
The endpoint I am using is "/api/user/change-password"
The request is as follows:
{
"applicationId": "f89b2e15-454b-4b1f-bb5f-7bfa83350823",
"currentPassword":"abcdefghij",
"loginId":"[email protected]",
"password":"12323123123",
"refreshToken":"YnfKX8T-Dl34VARDImN4-vVE_ueD__1YULtal6Xa9YrcKZeTlF3eog"
}
I can see in the lastest version of fusionauth there is a change in the changepasswordrequest. The new request struct in the client is as follows:
type ChangePasswordRequest struct {
BaseEventRequest
ApplicationId string json:"applicationId,omitempty"
ChangePasswordId string json:"changePasswordId,omitempty"
CurrentPassword string json:"currentPassword,omitempty"
LoginId string json:"loginId,omitempty"
Password string json:"password,omitempty"
RefreshToken string json:"refreshToken,omitempty"
TrustChallenge string json:"trustChallenge,omitempty"
TrustToken string json:"trustToken,omitempty"
}
Hello,
I am trying to send a LoginRequest to FusionAuth, with valid data I have tested. However, it returns an empty map.
&{map[] []}
It has only started doing this when I updated to FusionAuth 18.
When trying to create a new registration it's not possible set user to nil, resulting in default user's data being sent to /api/user/registration
causing Fusion to treat this request as Create user+Register
{
"generateAuthenticationToken": false,
"registration": {
"applicationId": "f252fdca-5cc6-42b9-b3d2-660008c08887",
"roles": ["owner"],
"verified": true
},
"sendSetPasswordEmail": false,
"skipRegistrationVerification": false,
"skipVerification": false,
"user": {
"passwordChangeRequired": false,
"twoFactorEnabled": false,
"verified": false,
"active": false
}
}
Since it's possible to access all rc client methods from outside the package, workaround is simple: just redefine structure with User *fusionauth.User
json:"user,omitempty"`` and copy-paste Register call. But it would be nice to have this fixed in the package.
Thanks for the awesome product, btw.
Would it be possible in cases where there is no body returned, 401 - Unauthorized
for instance, to return an error stating unexpected status code.
err = json.NewDecoder(resp.Body).Decode(rc.ErrorRef)
if err == io.EOF {
err = fmt.Errorf("unexpected status code: %d(%s)", resp.StatusCode, http.StatusText(resp.StatusCode))
}
Related Issue: FusionAuth/terraform-provider-fusionauth#3
I have created a tenant using Tenant APIs using the Default Tenant as a base, but trying to add customisations, in this case email settings.
POST api/tenant
{
"tenant": {
"sourceTenantId": "1477a639-1027-1fdb-b6cc-f19a162865a9",
"name": "foo",
"issuer":"foobar.com",
"emailConfiguration":{
"defaultFromEmail":"[email protected]",
"defaultFromName":"FooBar",
"host":"smtp.foobar.com",
"implicitEmailVerificationAllowed":false,
"password":"password",
"port":465,
"security":"SSL",
"username":"foobar"
},
"passwordEncryptionConfiguration":{
"encryptionScheme":"bcrypt",
"encryptionSchemeFactor":6
}
}
}
The result is satisfactory, as I get the new Tenant with the default configuration plus the customisations specified in the request.
On the other hand, when using the CreateTenant
method of the client, if I specify in the SourceTenantId
property the identifier of the base Tenant, the resulting Tenant does not have the custom properties.
func (h *Handler) CreateTenant(name string) (*fusionauth.TenantResponse, *fusionauth.Errors, error) {
tr := fusionauth.TenantRequest{
// if this property is uncommented, the result is the configuration of DefaultTenant
// SourceTenantId: "1477a639-1027-1fdb-b6cc-f19a162865a9",
Tenant: fusionauth.Tenant{
Name: name,
Issuer: "udrafter.com",
EmailConfiguration: fusionauth.EmailConfiguration{
DefaultFromEmail: "[email protected]",
DefaultFromName: "foobar",
Host: "smt.foobar.com",
ImplicitEmailVerificationAllowed: false,
Password: "password",
Port: 465,
Security: "SSL",
Username: "foobar",
},
PasswordEncryptionConfiguration: fusionauth.PasswordEncryptionConfiguration{
EncryptionScheme: "bcrypt",
EncryptionSchemeFactor: 6,
},
},
}
r, faerrors, err := h.FusionAuth.CreateTenant("", tr)
if err != nil {
return nil, faerrors, err
}
return r, faerrors, nil
}
I understand that this behaviour does not correspond to the behaviour obtained using Tenant APIs and to what is discussed in this section of the documentation:
sourceTenantId [UUID] OPTIONAL AVAILABLE SINCE 1.14.0
The optional Id of an existing Tenant to make a copy of. A unique tenant.name is required. If present, the tenant.id value will used for the new Tenant. All other values will be copied from the source Tenant to the new Tenant.
"Create a User Registration (for an existing user)"
Doesnt seem to work, because of
https://stackoverflow.com/questions/33447334/golang-json-marshal-how-to-omit-empty-nested-struct
(a User Object is always passed, even if its ommitted, causing your Client to want to create a new User)
Could you maybe change Domain.go line 2691 into a User-Pointer, like so?
type RegistrationRequest struct {
GenerateAuthenticationToken bool json:"generateAuthenticationToken"
Registration UserRegistration json:"registration,omitempty"
SendSetPasswordEmail bool json:"sendSetPasswordEmail"
SkipRegistrationVerification bool json:"skipRegistrationVerification"
SkipVerification bool json:"skipVerification"
User *User json:"user,omitempty"
}
Then it works.
hello.
when i use RegisterWithContext
func for the purpose of https://fusionauth.io/docs/v1/tech/apis/registrations#create-a-user-registration-for-an-existing-user such as
res, errs, err := faClient.RegisterWithContext(
ctx, userID, fusionauth.RegistrationRequest{
GenerateAuthenticationToken: true,
Registration: fusionauth.UserRegistration{
ApplicationId: applicationID,
Id: rID,
Username: uname,
},
SkipRegistrationVerification: true,
})
it always fails with errs.FieldErrors
of map[user.email:[{Code:[blank]user.email Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] user.password:[{Code:[blank]user.password Data:map[] Message:You must specify the [user.password] property.}] user.username:[{Code:[blank]user.username Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] userId:[{Code:[duplicate]userId Data:map[] Message:A User with Id [2bc3b58e-762a-40f8-b4cf-6dcc99ec09c8] already exists.}]]
which basically means that it simultaneously complains about user.email/user.password/user.username being empty and userId already existing (not a surprise, I didn't intend to create a new user).
however, when I do:
type faReg struct {
DisableDomainBlock bool `json:"disableDomainBlock"`
GenerateAuthenticationToken bool `json:"generateAuthenticationToken"`
Registration fusionauth.UserRegistration `json:"registration,omitempty"`
SendSetPasswordEmail bool `json:"sendSetPasswordEmail"`
SkipRegistrationVerification bool `json:"skipRegistrationVerification"`
SkipVerification bool `json:"skipVerification"`
}
func faDoReg(faClient *fusionauth.FusionAuthClient, ctx context.Context, userId string, request faReg) (*fusionauth.RegistrationResponse, *fusionauth.Errors, error) {
var resp fusionauth.RegistrationResponse
var errors fusionauth.Errors
restClient := faClient.Start(&resp, &errors)
err := restClient.WithUri("/api/user/registration").
WithUriSegment(userId).
WithJSONBody(request).
WithMethod(http.MethodPost).
Do(ctx)
if restClient.ErrorRef == nil {
return &resp, nil, err
}
return &resp, &errors, err
}
//...
res, errs, err := faDoReg(
faClient, ctx, userID, faReg{
GenerateAuthenticationToken: true,
Registration: fusionauth.UserRegistration{
ApplicationId: applicationID,
Id: rID,
Username: uname,
},
SkipRegistrationVerification: true,
})
//...
it works without issues, because User field was not included.
please consider making fusionauth.RegistrationRequest
User
field a pointer type so that omitempty
works, as it is ineffective for structs, and the existence of omitempty
here means that it was intended to be omittable.
After upgrading to the latest version I get the following compilation error:
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:4174:17: undefined: char
Fill out TODOs or delete if they do not make sense.
Hi, I am trying to fetch the init refresh token by the login api, but the refresh token in response is empty. Why?
code:
var credentials fusionauth.LoginRequest
credentials.LoginId = "xxxxxxxxx"
credentials.Password = "xxxxxx"
// Use FusionAuth Go client to login the user
response, _, err := auth.Login(credentials)
if err != nil {
panic(err)
}
response:
{
"statusCode":200,
"token":"xxxxxxxxxxxxxxxxxxxxxxx",
"user":{
"id":"04f1179f-f21e-4ab1-b5e1-0b565e8aedd4",
"passwordLastUpdateInstant":1577921277919,
"verified":true,
"active":true,
"email":"xxxxxxxx",
"insertInstant":1577921277858,
"lastLoginInstant":1579134696920,
"registrations":[
{
"applicationId":"3c219e58-ed0e-4b18-ad48-f4f92793ae32",
"id":"5a36c8ed-20e4-4390-9f4d-5dd017cbda0f",
"insertInstant":1577924008508,
"roles":[
"api_key_manager",
"application_deleter",
"application_manager",
"audit_log_viewer",
"lambda_manager",
"report_viewer",
"webhook_manager"
],
"usernameStatus":"ACTIVE",
"verified":true
},
{
"applicationId":"8af9b71b-5637-435c-9f4c-fb82e17dd114",
"id":"2a863715-4de2-4932-81a4-a37b298e4187",
"insertInstant":1577921854040,
"lastLoginInstant":1578960128426,
"username":"alon",
"usernameStatus":"ACTIVE",
"verified":true
}
],
"tenantId":"e0dede59-09ab-701b-e6da-8c7911ff6464",
"twoFactorDelivery":"None",
"username":"alon",
"usernameStatus":"ACTIVE"
}
}
The FusionAuth Go client, can hide errors if a response body is not received.
This issue can be replicated by providing a bad URL to the client constructor so that it always returns a 502 with no response body.
For example:
client := fusionauth.NewClient(nil, badUrlThatAlwaysReturnsEmpty502, apiKey)
// then, errors will be empty and err will be nil even though status code is 502
resp, errors, err := client.SearchEntitiesWithContext(ctx, req)
I think this is happening because on non 2XX response, the client intends to unmarshal the body into Errors
while setting error
to nil. This means, if there's nothing to unmarshal, both error
and Errors
end up being empty:
The Login API is supposed to sign-in a User and return a "Set-Cookie" header that contains the refresh token and access token, but the client does not read the headers from the response, nor does it return them.
A workaround is to call the login API yourself instead of using the go-client and reading the headers from the response.
func (rc *restClient) Do() error {
req, err := http.NewRequest("POST", rc.Uri.String(), rc.Body)
if err != nil {
return err
}
for key, val := range rc.Headers {
req.Header.Set(key, val)
}
resp, err := rc.HTTPClient.Do(req)
if err != nil {
return err
}
// Reading the headers from the response
key := resp.Header.Values("Set-Cookie")
if key != nil {
rc.Cookie = key
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return errors.BaseBadRequest
} else {
rc.ErrorRef = nil
if _, ok := rc.ResponseRef.(*BaseHTTPResponse); !ok {
err = json.NewDecoder(resp.Body).Decode(rc.ResponseRef)
}
}
return err
}
This is a workaround that I have used.
Hello,
Is it possible to have a full example of a little app with 2 routes to have an example of how use your library ?
Thank you very much,
Best regards
when i want to register user to and application I have a error and give me that user exist:
package main
import (
"github.com/FusionAuth/go-client/pkg/fusionauth"
"log"
"net/http"
"net/url"
)
func main() {
var HttpClient = &http.Client{}
u, _ := url.Parse("http://192.168.13.32:9011")
f := fusionauth.NewClient(HttpClient, u, "hBUKq3x_hUFXqA6GSXhdWWTRknTq7uzTNc_SzCmhpgDgm0UpNI-Wm56C")
r, e1, e2 := f.Register("e2337690-4c91-4573-bbed-88695701612f", fusionauth.RegistrationRequest{
Registration: fusionauth.UserRegistration{
ApplicationId: "dee6cf94-0bdc-4050-bca8-04ac1920ee9b",
Username: "dtd",
Roles: []string{"10"},
},
})
log.Println("response", r)
log.Println("des err : ", e1)
log.Println("err", e2)
}
and my error is:
user.email: You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email]. user.password: You must specify the [user.password] property. user.username: You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email]. userId: A User with Id [e2337690-4c91-4573-bbed-88695701612f] already exists.
The go client doesn't have the ability to add an application ID so we cant get back the refresh token.
https://fusionauth.io/docs/v1/tech/apis/login/
response, fusionAuthErr, err := auth.Auth.Login(fusionauth.LoginRequest{
LoginId: {{email}},
Password: {{password}},
})
Reference in API
/**
* Login API request object.
*
* @author Seth Musselman
*/
type LoginRequest struct {
BaseLoginRequest
LoginId string `json:"loginId,omitempty"`
OneTimePassword string `json:"oneTimePassword,omitempty"`
Password string `json:"password,omitempty"`
TwoFactorTrustId string `json:"twoFactorTrustId,omitempty"`
}
There's an error in conversion of integer value to string when retrieving an event log and an audit log.
Error from fusionAuth
{"fieldErrors":{"id":[{"code":"[couldNotConvert]id","message":"java.lang.NumberFormatException: For input string: \"\u0001\""}]},"generalErrors":[{"code":"[invalid]","message":"Your GET request is missing the Id on the URL."}]}
Conversion Issue Reproduced: https://play.golang.org/p/_AqXx9yf5VF
Go Version:
go version go1.13.4 darwin/amd64
FusionAuthClient API methods return a response
, errors
and err
.
The Example syntax advises to check errors
and err
for nil to determine if there were errors.
I was playing around with the newest go-client against a FusionAuth version 1.11.0 installation and discovered, that e.g.
CreateTenant
call, errors
is not nil but &{map[] []}
DeleteTenant
call, err
is not nil but EOF
and errors
is also &{map[] []}
Maybe I'm just a little confused, but shouldn't they be nil
?
Mentioned this on a previously opened issue, however I thought it'd be more appropriate to open a separate issue.
EOF is returned fairly often when the errors[map]interface{} object is just an empty map.
For example, retrieving a user by id with an id that doesn't exist returns EOF instead just returning a nil UserResponse.
A similar thing happens when you're logging into a user who's password hasn't been set and also when registering a user.
There's is a possibility I'm using the client incorrectly but the login example on the FusionAuth website will also return EOF when the user isn't registered to an application ID.
I realize some client functions add nil
error reference to the next call. For example: https://github.com/FusionAuth/go-client/blob/master/pkg/fusionauth/Client.go#L3420. Is that intentional? (But some other functions declare an error and pass it to the next call)
I had some bad experience with troubleshooting when I had the wrong FusionAuth API. Perhaps getting an explicit 401 error is more helpful?
After upgrading to the latest version I get the following compilation errors:
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:2858:16: undefined: double
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:2859:16: undefined: double
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:4453:16: undefined: double
WebhookIDs were added to the tenant in 1.37.0, but they're not in the SDK.
In the client the User
's BirthDate
field is declared as int64
(see here), while the documentation demands a string
(of format yyyy-MM-dd
in Java terms) (see here). Therefore, any requests aiming to create or modify a user and setting the BirthDate
on the way will fail. So, if I use the Go client to send a request to the API specifiying the birthdate, it will lead to an error message telling me the BirthDate could not be parsed at index 0.
I would fix that myself and create a pull request, but since the clients are generated that wouldn't help much, would it?
According to the documentation, not only registrations contain verified
and verifiedInstant
fields, but the user itself. But the Go implementation is missing such fields in User struct.
I just installed the library, and I am getting an issue with your library in the compilation of my project.
..\..\..\pkg\mod\github.com\!fusion!auth\[email protected]\pkg\fusionauth\Domain.go:1838:6: LambdaConfiguration redeclared in this block
previous declaration at ..\..\..\pkg\mod\github.com\!fusion!auth\[email protected]\pkg\fusionauth\Domain.go:1832:6```
Using the savant release plugin, I see that this client library has releases (1.29.0
, 1.28.0
) and tags with the same format.
However, the golang way is to preface the version with a v
: v1.29.0
. This is documented here: https://blog.golang.org/publishing-go-modules and here: https://golang.org/doc/modules/version-numbers
I reviewed the release git plugin ( http://savantbuild.org/docs/plugins/release-git/ ) but was unable to determine how to modify the build.savant file to prepend that v
.
This matters because when you pull in the lib as a go module, you are not able to pull in a specific version by tag. Instead, your go.mod
file looks like:
% cat go.mod
module example.com/test/fusionauth
go 1.16
require github.com/FusionAuth/go-client v0.0.0-20210806213402-4c80b3657d94
Discovered in the course of this: FusionAuth/fusionauth-site#867
Is there a way to create identity-provider using golang client. I don't see any implementation in client.go for creating one.
This API: https://github.com/FusionAuth/go-client/blob/master/pkg/fusionauth/Client.go#L290 has the functionality to:
// ChangePasswordByIdentity
// Changes a user's password using their identity (login id and password). Using a loginId instead of the changePasswordId
// bypasses the email verification and allows a password to be changed directly without first calling the #forgotPassword
// method.
// ChangePasswordRequest request The change password request that contains all of the information used to change the password.
If I do not pass the current_password in this API, it still changes the user's password without the current password. If I pass something as current_password in the request it does check if it matches the user's current password.
The abnormal behavior happens when nothing is passed as current_password.
Similarly, in the fusionauth dashboard, I can change any User's password without the previous password. Is this behavior intended?
Or are these 2 issues related and pointing to a bigger overall problem with how fusionauth changes passwords.
API response from /api/webauthn/register/start
:
{
"options": {
"pubKeyCredParams": [
{
"alg": -36,
"type": "public-key"
},
{
"alg": -35,
"type": "public-key"
},
...
}
}
Golang type:
type PublicKeyCredentialParameters struct {
Alg CoseAlgorithmIdentifier `json:"alg,omitempty"`
Type PublicKeyCredentialType `json:"type,omitempty"`
}
...
type CoseAlgorithmIdentifier string
func (e CoseAlgorithmIdentifier) String() string {
return string(e)
}
const (
CoseAlgorithmIdentifier_ES256 CoseAlgorithmIdentifier = "ES256"
CoseAlgorithmIdentifier_ES384 CoseAlgorithmIdentifier = "ES384"
CoseAlgorithmIdentifier_ES512 CoseAlgorithmIdentifier = "ES512"
CoseAlgorithmIdentifier_RS256 CoseAlgorithmIdentifier = "RS256"
CoseAlgorithmIdentifier_RS384 CoseAlgorithmIdentifier = "RS384"
CoseAlgorithmIdentifier_RS512 CoseAlgorithmIdentifier = "RS512"
CoseAlgorithmIdentifier_PS256 CoseAlgorithmIdentifier = "PS256"
CoseAlgorithmIdentifier_PS384 CoseAlgorithmIdentifier = "PS384"
CoseAlgorithmIdentifier_PS512 CoseAlgorithmIdentifier = "PS512"
)
Error:
cannot unmarshal number into Go struct field PublicKeyCredentialParameters.options.pubKeyCredParams.alg of type fusionauth.CoseAlgorithmIdentifier
Getting compile error because two structs have the same name in commit "rebuild domain after removing omitempty from bool types. Fix for #22", master branch, committed yesterday
1 parent b6a7bd6 commit 25495fe
Error is:
github.com/FusionAuth/go-client/pkg/fusionauth
../../../../pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:1754:6: LambdaConfiguration redeclared in this block
previous declaration at ../../../../pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:1748:6
type LambdaConfiguration struct {
AccessTokenPopulateId string `json:"accessTokenPopulateId,omitempty"`
IdTokenPopulateId string `json:"idTokenPopulateId,omitempty"`
Samlv2PopulateId string `json:"samlv2PopulateId,omitempty"`
}
type LambdaConfiguration struct {
ReconcileId string `json:"reconcileId,omitempty"`
}
My guess is this is a merge issue and the LambdaConfiguration struct should look like this:
type LambdaConfiguration struct {
AccessTokenPopulateId string `json:"accessTokenPopulateId,omitempty"`
IdTokenPopulateId string `json:"idTokenPopulateId,omitempty"`
ReconcileId string `json:"reconcileId,omitempty"`
Samlv2PopulateId string `json:"samlv2PopulateId,omitempty"`
}
Hi,
I have begun work on this in a Fork, here https://github.com/JohnLockwood/fusionauth-go-client.
It's very preliminary so far but I'll be pushing updates to the fork as I do them if folks want to check progress. The intent will be to do a pull request back here when it's more complete.
Thanks!
In some case (eg. automation), we don't need to log in with a specific user but use directly an "admin api key".
Is there a way to use client method without pre-auth of a user, like we can do directly with an api key and and REST client ? If so, I didn't found any documentation for this.
Regards.
Would it possible to return nil for
fusionauth.Errors
instead of &{map[] []} when no errors are present during validation?
Today, after upgrading to the latest version I got the following compilation errors:
github.com/FusionAuth/go-client/pkg/fusionauth
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Client.go:4637:81: undefined: UserinfoResponse
../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Client.go:4638:11: undefined: UserinfoResponse
Maybe I am doing something wrong but this function doesn't seem to be working. I cant seem to make it work with the API key sent which I think this function below is trying to do.
https://fusionauth.io/docs/v1/tech/apis/jwt#retrieve-refresh-tokens
// RetrieveRefreshTokens
// Retrieves the refresh tokens that belong to the user with the given Id.
// string userId The Id of the user.
func (c *FusionAuthClient) RetrieveRefreshTokens(userId string) (*RefreshResponse, *Errors, error) {
var resp RefreshResponse
var errors Errors
restClient := c.Start(&resp, &errors)
err := restClient.WithUri("/api/jwt/refresh").
WithParameter("userId", userId).
WithMethod(http.MethodGet).
Do()
if restClient.ErrorRef == nil {
return &resp, nil, err
}
return &resp, &errors, err
}
Hi Y'all
So encountered an issue where if you have
Default tenant
Specific tenant
a user created on the default tenant
and you make a request to a specific tenant and not the default aka pass in the wrong tenant id
fusionauth.Errors will return a &map[] []{} and err with be an EOF will no helpful error regarding the issue. A more appropriate response could be to return a 403 as part of the fusionauth.LoginResponse which contains a statusCode.
Much appreciated.
When trying to do curl [GET] request to validate:
{
"jwt": {
"exp": 1606240095,
"iat": 1606236495,
"iss": "acme.com",
"jti": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX",
"sub": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX",
"authenticationType": "PASSWORD",
"email": "[email protected]",
"email_verified": true,
"preferred_username": "domgolonka"
}
}
The above shows the email, email_verified, preferred_username, & authenticationType fields.
When trying to it using the client:
*fusionauth.JWT=&{<nil> 1606238646 1606235046 acme.com XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX 0 map[] XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX})
There are missing fields from the above.
Currently due to the serialization / de-serialization complexity of the IdP APIs, they are omitted from this client.
Here are the APIs we are skipping at the moment:
https://github.com/FusionAuth/fusionauth-client-builder/blob/462c2ca09bb291581164f383428ae276645ace55/src/main/client/go.client.ftl#L186
If we could figure out how to make this work in Go, we would add them.
Here is an example solution provided by @MCBrandenburg https://play.golang.org/p/7ZBAbrDo98w
I had just recently upgraded to 1.39.0 from 1.38.1. When I try to call this method on the client:
func (c *FusionAuthClient) RetrieveApplication(applicationId string) (*ApplicationResponse, error) {
var resp ApplicationResponse
err := c.Start(&resp, nil).
WithUri("/api/application").
WithUriSegment(applicationId).
WithMethod(http.MethodGet).
Do()
return &resp, err
}
I am getting the following error: Invalid [Content-Type] HTTP request header value of [text/plain]. Supported values for this request include [application/json].
I believe the issue is this line:
https://github.com/FusionAuth/go-client/blob/master/pkg/fusionauth/Client.go#L91
When I change the code to utilize application/json
for the Content-Type
, my integration tests work. This likely impacts all API calls, but I did not test to validate this.
These calls used to work on 1.38.1.
Hi,
I'm trying to use the client but have some question, need some help.
My goal is to grab all the last events, login..., from a specific user based on his email by example.
So if we take this for example:
response, errors, err := client.SearchEventLogs()
the module explaintion gove me that:
func (*fusionauth.FusionAuthClient).SearchEventLogs(request fusionauth.EventLogSearchRequest) (*fusionauth.EventLogSearchResponse, *fusionauth.Errors, error)
SearchEventLogs Searches the event logs with the specified criteria and pagination.
EventLogSearchRequest request The search criteria and pagination information.
(fusionauth.FusionAuthClient).SearchEventLogs on pkg.go.dev
but what is the function input ?? What does refer the struct linked to request fusionauth.EventLogSearchRequest ?
Ty,
Adrien
Incorrect Event Type strings https://godoc.org/github.com/FusionAuth/fusionauth-go-client/pkg/fusionauth#EventType. They should be user.update
, user.delete
, user.create
, etc as seen in the API docs here: https://fusionauth.io/docs/v1/tech/apis/webhooks#create-a-webhook.
Shouldn't this method use StartAnonymous()
?
Currently it's using an API-Key and I always run into a 401 without further information.
Checking the API manually (with a REST client) it seems that providing an API Key is the cause for the 401.
Instead of API Key, the API wants an X-FusionAuth-TenantId
in the header.
How to achieve that using the go-client? Can I create a client using NewClient()
without an API Key and set its headers?
Thanks in advance!
go-client/pkg/fusionauth/Client.go
Line 2685 in 7e32142
I think the method ExchangeOAuthCodeForAccessToken() is not taking care of the optional params clientID
and clientSecret
. I'm using the values "" (my take of optional), yet the response of FA is:
The request is missing a required parameter: client_id missing_client_id
After upgrading to the latest version I get the following compilation error:
% github.com/FusionAuth/go-client/pkg/fusionauth
../../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:2031:6: JWTConfiguration redeclared in this block
previous declaration at ../../../../go/pkg/mod/github.com/!fusion!auth/[email protected]/pkg/fusionauth/Domain.go:2017:6
FusionAuthClient API methods return a response
, errors
and err
.
The Example syntax advises to check errors
and err
for nil to determine if there were errors.
I was playing around with the newest go-client against a FusionAuth version 1.11.0 installation and discovered, that e.g.
after a successful CreateTenant()
call (HTTP 200), errors
is not nil but &{map[] []}
after a successful DeleteTenant()
call (HTTP 200), err
is not nil but EOF
and errors is also &{map[] []}
Maybe I'm just a little confused, but shouldn't they be nil?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.