mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 01:48:22 +00:00
Merge pull request #17 from lenforiee/fix-spelling-mistakes
Fix spelling mistakes in the code
This commit is contained in:
commit
e4537a8ca0
7 changed files with 33 additions and 31 deletions
10
README.md
10
README.md
|
@ -1,4 +1,5 @@
|
|||
# go-passbolt
|
||||
|
||||
[](https://pkg.go.dev/github.com/passbolt/go-passbolt)
|
||||
|
||||
A Go module to interact with [Passbolt](https://www.passbolt.com/), an open-source password manager for teams
|
||||
|
@ -19,12 +20,12 @@ PR's are welcome. But be gentle: if it's something bigger or fundamental: please
|
|||
|
||||
Disclaimer: This project is community driven and not associated with Passbolt SA
|
||||
|
||||
|
||||
# Install
|
||||
|
||||
`go get github.com/passbolt/go-passbolt`
|
||||
|
||||
# Examples
|
||||
|
||||
## Login
|
||||
|
||||
First, you will need to create a client and then log in on the server using the client:
|
||||
|
@ -214,6 +215,7 @@ err = helper.UpdateUser(
|
|||
"lastname", // LastName
|
||||
)
|
||||
```
|
||||
|
||||
Note: These helpers will only update fields that are not "".
|
||||
|
||||
Helper update functions also exists for Folders.
|
||||
|
@ -227,7 +229,7 @@ During sharing you will encounter the [permission type](https://github.com/passb
|
|||
The `permissionType` can be:
|
||||
|
||||
| Code | Meaning |
|
||||
| --- | --- |
|
||||
| ---- | -------------------------- |
|
||||
| `1` | "Read-only" |
|
||||
| `7` | "Can update" |
|
||||
| `15` | "Owner" |
|
||||
|
@ -294,6 +296,7 @@ err := client.MoveFolder(ctx, "folder id", "parent folder id")
|
|||
## Setup
|
||||
|
||||
You can setup a Account using a Invite Link like this:
|
||||
|
||||
```go
|
||||
// Get the UserID and Token from the Invite Link
|
||||
userID, token, err := ParseInviteUrl(url)
|
||||
|
@ -327,13 +330,12 @@ if err != nil {
|
|||
|
||||
## MFA
|
||||
|
||||
go-passbolt now supports MFA! You can set it up using the Client's `MFACallback` function, it will provide everything you need to complete any MFA challanges. When your done you just need to return the new MFA Cookie (usually called passbolt_mfa). The helper package has a example implementation for a noninteractive TOTP Setup under helper/mfa.go in the function `AddMFACallbackTOTP`.
|
||||
go-passbolt now supports MFA! You can set it up using the Client's `MFACallback` function, it will provide everything you need to complete any MFA challenges. When your done you just need to return the new MFA Cookie (usually called passbolt_mfa). The helper package has a example implementation for a noninteractive TOTP Setup under helper/mfa.go in the function `AddMFACallbackTOTP`.
|
||||
|
||||
## Other
|
||||
|
||||
These examples are just the main use cases of these Modules, many more API calls are supported. Look at the [reference](https://pkg.go.dev/github.com/passbolt/go-passbolt) for more information.
|
||||
|
||||
|
||||
## Full Example
|
||||
|
||||
This example:
|
||||
|
|
|
@ -64,7 +64,7 @@ start:
|
|||
} else if res.Header.Status == "error" {
|
||||
if res.Header.Code == 403 && res.Header.URL == "/mfa/verify/error.json" {
|
||||
if !firstTime {
|
||||
// if we are here this probably means that the MFA callback is broken, to prevent a infinit loop lets error here
|
||||
// if we are here this probably means that the MFA callback is broken, to prevent a infinite loop lets error here
|
||||
return r, &res, fmt.Errorf("Got MFA challenge twice in a row, is your MFA Callback broken? Bailing to prevent loop...:")
|
||||
}
|
||||
if c.MFACallback != nil {
|
||||
|
@ -72,11 +72,11 @@ start:
|
|||
if err != nil {
|
||||
return r, &res, fmt.Errorf("MFA Callback: %w", err)
|
||||
}
|
||||
// ok, we got the MFA challange and the callback presumably handeld it so we can retry the original request
|
||||
// ok, we got the MFA challenge and the callback presumably handled it so we can retry the original request
|
||||
firstTime = false
|
||||
goto start
|
||||
} else {
|
||||
return r, &res, fmt.Errorf("Got MFA Challange but the MFA callback is not defined")
|
||||
return r, &res, fmt.Errorf("Got MFA Challenge but the MFA callback is not defined")
|
||||
}
|
||||
}
|
||||
return r, &res, fmt.Errorf("%w: Message: %v, Body: %v", ErrAPIResponseErrorStatusCode, res.Header.Message, string(res.Body))
|
||||
|
|
|
@ -31,7 +31,7 @@ type Client struct {
|
|||
userPublicKey string
|
||||
userID string
|
||||
|
||||
// used for solving MFA challanges. You can block this to for example wait for user input.
|
||||
// used for solving MFA challenges. You can block this to for example wait for user input.
|
||||
// You shouden't run any unrelated API Calls while you are in this callback.
|
||||
// You need to Return the Cookie that Passbolt expects to verify you MFA, usually it is called passbolt_mfa
|
||||
MFACallback func(ctx context.Context, c *Client, res *APIResponse) (http.Cookie, error)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package api
|
||||
|
||||
type MFAChallange struct {
|
||||
type MFAChallenge struct {
|
||||
Provider MFAProviders `json:"providers,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,6 @@ type MFAProviders struct {
|
|||
TOTP string `json:"totp,omitempty"`
|
||||
}
|
||||
|
||||
type MFAChallangeResponse struct {
|
||||
type MFAChallengeResponse struct {
|
||||
TOTP string `json:"totp,omitempty"`
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (c *Client) SetupServerVerification(ctx context.Context) (string, string, e
|
|||
token := "gpgauthv1.3.0|36|" + uuid.String() + "|gpgauthv1.3.0"
|
||||
encToken, err := c.EncryptMessageWithPublicKey(serverKey, token)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Encrypting Challange: %w", err)
|
||||
return "", "", fmt.Errorf("Encrypting Challenge: %w", err)
|
||||
}
|
||||
err = c.VerifyServer(ctx, token, encToken)
|
||||
if err != nil {
|
||||
|
@ -57,7 +57,7 @@ func (c *Client) VerifyServer(ctx context.Context, token, encToken string) error
|
|||
}
|
||||
raw, _, err := c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "/auth/verify.json", "v2", data, nil)
|
||||
if err != nil && !strings.Contains(err.Error(), "The authentication failed.") {
|
||||
return fmt.Errorf("Sending Verification Challange: %w", err)
|
||||
return fmt.Errorf("Sending Verification Challenge: %w", err)
|
||||
}
|
||||
|
||||
if raw.Header.Get("X-GPGAuth-Verify-Response") != token {
|
||||
|
|
|
@ -14,7 +14,7 @@ type GroupMembershipOperation struct {
|
|||
Delete bool
|
||||
}
|
||||
|
||||
// GroupMembership containes who and what kind of membership they have with a group
|
||||
// GroupMembership contains who and what kind of membership they have with a group
|
||||
type GroupMembership struct {
|
||||
UserID string
|
||||
Username string
|
||||
|
|
|
@ -14,12 +14,12 @@ import (
|
|||
// AddMFACallbackTOTP adds a MFA callback to the client that generates OTP Codes on demand using a Token with configurable retries and delay
|
||||
func AddMFACallbackTOTP(c *api.Client, retrys uint, retryDelay, offset time.Duration, token string) {
|
||||
c.MFACallback = func(ctx context.Context, c *api.Client, res *api.APIResponse) (http.Cookie, error) {
|
||||
challange := api.MFAChallange{}
|
||||
err := json.Unmarshal(res.Body, &challange)
|
||||
challenge := api.MFAChallenge{}
|
||||
err := json.Unmarshal(res.Body, &challenge)
|
||||
if err != nil {
|
||||
return http.Cookie{}, fmt.Errorf("Parsing MFA Challange")
|
||||
return http.Cookie{}, fmt.Errorf("Parsing MFA Challenge")
|
||||
}
|
||||
if challange.Provider.TOTP == "" {
|
||||
if challenge.Provider.TOTP == "" {
|
||||
return http.Cookie{}, fmt.Errorf("Server Provided no TOTP Provider")
|
||||
}
|
||||
for i := uint(0); i < retrys+1; i++ {
|
||||
|
@ -28,14 +28,14 @@ func AddMFACallbackTOTP(c *api.Client, retrys uint, retryDelay, offset time.Dura
|
|||
if err != nil {
|
||||
return http.Cookie{}, fmt.Errorf("Error Generating MFA Code: %w", err)
|
||||
}
|
||||
req := api.MFAChallangeResponse{
|
||||
req := api.MFAChallengeResponse{
|
||||
TOTP: code,
|
||||
}
|
||||
var raw *http.Response
|
||||
raw, _, err = c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "mfa/verify/totp.json", "v2", req, nil)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != api.ErrAPIResponseErrorStatusCode {
|
||||
return http.Cookie{}, fmt.Errorf("Doing MFA Challange Response: %w", err)
|
||||
return http.Cookie{}, fmt.Errorf("Doing MFA Challenge Response: %w", err)
|
||||
}
|
||||
// MFA failed, so lets wait just let the loop try again
|
||||
time.Sleep(retryDelay)
|
||||
|
@ -49,6 +49,6 @@ func AddMFACallbackTOTP(c *api.Client, retrys uint, retryDelay, offset time.Dura
|
|||
return http.Cookie{}, fmt.Errorf("Unable to find Passbolt MFA Cookie")
|
||||
}
|
||||
}
|
||||
return http.Cookie{}, fmt.Errorf("Failed MFA Challange 3 times: %w", err)
|
||||
return http.Cookie{}, fmt.Errorf("Failed MFA Challenge 3 times: %w", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue