-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from rusq/v3-auth-logic
Authentication
- Loading branch information
Showing
35 changed files
with
746 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package auth | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/rusq/slackdump/v3/internal/structures" | ||
) | ||
|
||
func parseDotEnv(fsys fs.FS, filename string) (string, string, error) { | ||
const ( | ||
tokenKey = "SLACK_TOKEN" | ||
cookieKey = "SLACK_COOKIE" | ||
|
||
clientTokenPrefix = "xoxc-" | ||
) | ||
f, err := fsys.Open(filename) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
defer f.Close() | ||
secrets, err := godotenv.Parse(f) | ||
if err != nil { | ||
return "", "", errors.New("not a secrets file") | ||
} | ||
token, ok := secrets[tokenKey] | ||
if !ok { | ||
return "", "", errors.New("no SLACK_TOKEN found in the file") | ||
} | ||
if err := structures.ValidateToken(token); err != nil { | ||
return "", "", err | ||
} | ||
if !strings.HasPrefix(token, clientTokenPrefix) { | ||
return token, "", nil | ||
} | ||
cook, ok := secrets[cookieKey] | ||
if !ok { | ||
return "", "", errors.New("no SLACK_COOKIE found in the file") | ||
} | ||
if !strings.HasPrefix(cook, "xoxd-") { | ||
return "", "", errors.New("invalid cookie") | ||
} | ||
return token, cook, nil | ||
} | ||
|
||
func ParseDotEnv(filename string) (string, string, error) { | ||
dir := filepath.Dir(filename) | ||
dirfs := os.DirFS(dir) | ||
pth := filepath.Base(filename) | ||
return parseDotEnv(dirfs, pth) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Workspace Import Command | ||
|
||
**Import** allows you to import credentials from a .env or secrets.txt file. | ||
|
||
It requires the file to have the following format: | ||
``` | ||
SLACK_TOKEN=xoxc-... | ||
SLACK_COOKIE=xoxd-... | ||
``` | ||
|
||
`SLACK_TOKEN` can be one of the following: | ||
|
||
- xoxa-...: app token | ||
- xoxb-...: bot token | ||
- xoxc-...: client token | ||
- xoxe-...: export token | ||
- xoxp-...: legacy user token | ||
|
||
`SLACK_COOKIE` is only required, if the `SLACK_TOKEN` is a client type token | ||
(starts with `xoxc-`). | ||
|
||
It will test the provided credentials, and if successful, encrypt and save | ||
them to the to the slackdump credential storage. It is recommended to delete | ||
the .env file afterwards. |
Oops, something went wrong.