diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 237adae..23b6098 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -6,8 +6,6 @@ on: branches: - main pull_request: - branches: - - main workflow_dispatch: inputs: command: diff --git a/build.savant b/build.savant index ecabfe0..875f25b 100644 --- a/build.savant +++ b/build.savant @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2024, FusionAuth, All Rights Reserved + * Copyright (c) 2019-2025, FusionAuth, All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ target(name: "format", description: "Formats the source code") { def process = pb.start() process.consumeProcessOutput(System.out, System.err) - process.waitFor() + assert process.waitFor() == 0 } target(name: "compile", description: "Compiles the source code", dependsOn: ["format"]) { diff --git a/pkg/fusionauth/Client.go b/pkg/fusionauth/Client.go index a753c74..e1512fe 100644 --- a/pkg/fusionauth/Client.go +++ b/pkg/fusionauth/Client.go @@ -7008,6 +7008,36 @@ func (c *FusionAuthClient) RetrieveUserByLoginIdWithContext(ctx context.Context, return &resp, &errors, err } +// RetrieveUserByLoginIdWithLoginIdTypes +// Retrieves the user for the loginId, using specific loginIdTypes. +// +// string loginId The email or username of the user. +// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. +func (c *FusionAuthClient) RetrieveUserByLoginIdWithLoginIdTypes(loginId string, loginIdTypes []string) (*UserResponse, *Errors, error) { + return c.RetrieveUserByLoginIdWithLoginIdTypesWithContext(context.TODO(), loginId, loginIdTypes) +} + +// RetrieveUserByLoginIdWithLoginIdTypesWithContext +// Retrieves the user for the loginId, using specific loginIdTypes. +// +// string loginId The email or username of the user. +// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. +func (c *FusionAuthClient) RetrieveUserByLoginIdWithLoginIdTypesWithContext(ctx context.Context, loginId string, loginIdTypes []string) (*UserResponse, *Errors, error) { + var resp UserResponse + var errors Errors + + restClient := c.Start(&resp, &errors) + err := restClient.WithUri("/api/user"). + WithParameter("loginId", loginId). + WithParameter("loginIdTypes", loginIdTypes). + WithMethod(http.MethodGet). + Do(ctx) + if restClient.ErrorRef == nil { + return &resp, nil, err + } + return &resp, &errors, err +} + // RetrieveUserByUsername // Retrieves the user for the given username. // @@ -7344,6 +7374,47 @@ func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdWithContext(ctx conte return &resp, &errors, err } +// RetrieveUserLoginReportByLoginIdAndLoginIdTypes +// Retrieves the login report between the two instants for a particular user by login Id, using specific loginIdTypes. If you specify an application id, it will only return the +// login counts for that application. +// +// string applicationId (Optional) The application id. +// string loginId The userId id. +// int64 start The start instant as UTC milliseconds since Epoch. +// int64 end The end instant as UTC milliseconds since Epoch. +// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. +func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdAndLoginIdTypes(applicationId string, loginId string, start int64, end int64, loginIdTypes []string) (*LoginReportResponse, *Errors, error) { + return c.RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext(context.TODO(), applicationId, loginId, start, end, loginIdTypes) +} + +// RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext +// Retrieves the login report between the two instants for a particular user by login Id, using specific loginIdTypes. If you specify an application id, it will only return the +// login counts for that application. +// +// string applicationId (Optional) The application id. +// string loginId The userId id. +// int64 start The start instant as UTC milliseconds since Epoch. +// int64 end The end instant as UTC milliseconds since Epoch. +// []string loginIdTypes the identity types that FusionAuth will compare the loginId to. +func (c *FusionAuthClient) RetrieveUserLoginReportByLoginIdAndLoginIdTypesWithContext(ctx context.Context, applicationId string, loginId string, start int64, end int64, loginIdTypes []string) (*LoginReportResponse, *Errors, error) { + var resp LoginReportResponse + var errors Errors + + restClient := c.Start(&resp, &errors) + err := restClient.WithUri("/api/report/login"). + WithParameter("applicationId", applicationId). + WithParameter("loginId", loginId). + WithParameter("start", strconv.FormatInt(start, 10)). + WithParameter("end", strconv.FormatInt(end, 10)). + WithParameter("loginIdTypes", loginIdTypes). + WithMethod(http.MethodGet). + Do(ctx) + if restClient.ErrorRef == nil { + return &resp, nil, err + } + return &resp, &errors, err +} + // RetrieveUserRecentLogins // Retrieves the last number of login records for a user. // diff --git a/pkg/fusionauth/Client_test.go b/pkg/fusionauth/Client_test.go index 859d401..f7b8d17 100644 --- a/pkg/fusionauth/Client_test.go +++ b/pkg/fusionauth/Client_test.go @@ -60,6 +60,28 @@ func TestRetrieveUserSuccess(t *testing.T) { assert.Equal(t, 200, userResponse.StatusCode) } +func TestRetrieveUserByLoginIdSuccess(t *testing.T) { + loginIdTypes := []string{"email"} + + userResponse, errors, _ := faClient.RetrieveUserByLoginIdWithLoginIdTypes("richard@example.com", loginIdTypes) + errJson, _ := json.Marshal(errors) + fmt.Println(string(errJson)) + + assert.Equal(t, (*Errors)(nil), errors) + assert.Equal(t, 200, userResponse.StatusCode) +} + +// TODO: Will pass when issue 1 is released +// func TestRetrieveUserByLoginIdWrongIdentityType(t *testing.T) { +// loginIdTypes := []string{"phoneNumber"} +// +// userResponse, errors, _ := faClient.RetrieveUserByLoginIdWithLoginIdTypes("richard@example.com", loginIdTypes) +// errJson, _ := json.Marshal(errors) +// fmt.Println(string(errJson)) +// +// assert.Equal(t, 404, userResponse.StatusCode) +// } + func TestMain(m *testing.M) { os.Exit(m.Run()) }