Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add password flag for authentication #43

wants to merge 52 commits into
base: master


Copy link

commented Sep 6, 2019

For T692

robjloranger and others added 30 commits Jun 7, 2019
add new wf binary for community instances
this creates a second binary, wf, which will have additonal
functionality for hosts other than

also moves global flags into their own slice in new file

adds `host, H` global flag

inlcudes gitignore for binary
store/load user with host specific sub folder
only if host flag supplied for writefreely binary, writeas unaffected
fix bug with creating empty dir in working dir
some changes resulted in the data directory initialization creating the
.writeas/.writefreely directory in the current working directory.
start multi user authentication
- adds new user/u flag to wf
- load and save user file based on username
- removed host flag from writeas
- adds hidden global flag for user to writeas to maintain
multiple user authentication
- now allows authentication with more than one user per host, stored as
username.json inside the [host] directory.
- supports a default user and host in config.ini
- global flags will override the default
support any writefreely instance
full support, auth and actions working by use of flags or defaults
maintains backwards compatibility with
wf: remove fetch and add blogs cmd
this get's the wf binary up to date with the writeas functionality
store user.json in user sub folder
only on wf, writeas still stores in root user config directory
bugfix: default user should work on other domains
there was a bug where a default user at the config directory root was
not being used for calls not including a flag or host level config.ini
include new claim cmd in wf
also update CmdClaim for new LoadUser signiture
revert global flag change
I had changed the global flags variable to only be those that are global
this broke some compatibility with piping from stdout into the binary.

- binary specific configuration details have moved into the same map but
in main.go. only the configDir is OS dependent.
- a new key in the map is for the version so each binary can have their
local posts should use host dir
also CmdPost should return an exit error if there is one
use v2.0.1 go-writeas
for inclusion of collection in post parameters
default to user collection
new posts, when no flag is specified for blog or collection, will now
default to the user collection. that is the username.
add config.TorURL
select tor URL based on provided host flag, default host in config or
default onion address. in that order of precedence.
update wf binary flags to include tor
all network calls should respect tor when set
update note about user and host flags
previously was calling the new `wf` binary the community edition, now
just called `writefreely`
Change mentions of in wf cmd to WriteFreely
Particularly, in command descriptions.
CmdListPosts: update use of LoadUser
config.LoadUser now only takes a *cli.Context
fix LoadUser directory does not exist
config.LoadUser was not ensuring the directory exists before trying to
load any already authenticated user, fixed using config.DirMustExist
Accept --host without scheme
This automatically prepends https:// to any given --host value. It also
adds an --insecure flag, which will instead prepend http://

The goal with this is to save some typing and encourage operations over

Ref T595
thebaer and others added 21 commits Jul 22, 2019
Don't default host to in wf-cli
We want to keep wf-cli service-agnostic and to make sure there's no
confusing overlap between this client and writeas-cli.

Ref T586
Output full URL publishing with --host flag
Now that no scheme is required, we need to use the helper function to
include it, instead of the raw --host value. This does that.

Ref T595
Require authentication for post operations in wf
Unlike, WriteFreely doesn't support anonymous (unauthenticated)
publishing. With these changes, we reflect that in wf-cli by wrapping
creating, updating, and deleting posts in a func that checks
authentication state.

Ref T586
Reflect wf-cli/writeas-cli in User-Agent
Previously, this would always include writeas-cli.

Ref T586
Automatically set WF account as default on first auth
Now when running `wf auth`, we'll automatically set the given host +
username as the default account in .writefreely/config.ini, so subsequent
requests without an explicit --host and --user will use this account.

Ref T635 T586
Remove `add` action from wf-cli
WriteFreely doesn't support non-auth'd posting like, so users
won't be creating non-auth'd posts with another client that they'd need
to add here.

Ref T586
Clean up directories on `wf logout`
On logout, this deletes host / user directories if they're empty.

Ref T586
move LoadUser call out of newClient
to start on a fix for user actions when logged in with one user on a
given host with the wf binary, a user should now only be loaded by the
caller of newClient.

newClient no longer takes a bool for authRequired, all calls
updated to new signature and load the user where required.
export UserHostDir
for use outside of package
helper func for logged in users
this function checks the host based path for any logged in users and
returns the number or users, a list of usernames and an error if any
update requireAuth helper, check logged in users
this uses the usersLoggedIn helper to check for already logged in users,
selecting the single user when only one present and returning and error
when multiple are logged in.
CurrentUser only use global when needed
by needed: when host flag was supplied, matches that configured and a
user is set in config as well. they should be a pair.
newClient must prepend scheme to default host
this updates newClient to prepend the scheme https to the default host
found in the global config, and only use said host when both the user
and host are configured
use default user when authenticating
if both a user and host are configured, the command auth should assume
that user and host when none specified
do not parse url from configured host
now that the scheme is not required in the configuration file, we can
assume the configured value is correct. as with other uses, the
configured value is only used when noth host and user are present.
wf check for config when auth required
this adds a check for configured defaults during the command pre check
when authentication is required. using the values found if both are
present and only if both flags are ommitted.
CurrentUser should always return the flag if set
previously when the user flag was provided, the function would still try
to get a user from config. flag should take precedence
command auth should use user flag
if the user flag is provided auth should attempt to authenticate with
that user.
Copy link

left a comment

Thanks for tackling this, Chris. Here's a few things that need to be addressed based on reading through the code.

Going forward, let's just be sure to test our changes for regressions before opening pull requests. And let me know if anything's unclear.

commands/commands.go Outdated Show resolved Hide resolved
commands/commands.go Outdated Show resolved Hide resolved
commands: Fix up the interactive auth flow
Fixes up the interactive authorization workflow so that
pass is reassigned properly.

For T692

This comment has been minimized.

Copy link

commented Sep 9, 2019

Perfect, code looks good now 👍

Last thing I'd suggest is removing the redundant string() cast on line 408 in commands.go -- then I'll test this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.