Merge remote-tracking branch 'upstream/develop' into mckael-experiments_2
Conflicts:
cmd/gondole-cli/main.go
--- a/cmd/gondole-cli/main.go Wed Apr 12 18:28:39 2017 +0200
+++ b/cmd/gondole-cli/main.go Wed Apr 12 22:26:52 2017 +0200
@@ -13,6 +13,7 @@
var (
fVerbose bool
fInstance string
+ fAuthMethod string
fUsername, fPassword string
fScopes string
@@ -27,6 +28,11 @@
}
defaultInstanceURL = "https://mastodon.social"
+
+ authMethods = map[string]bool{
+ "basic": true,
+ "oauth2": true,
+ }
)
// Server holds our application details
@@ -40,9 +46,17 @@
type Config struct {
Default string
+
+ // Can be "oauth2", "basic"
+ Auth string
+
+ // If not using OAuth2
+ User string
+ Password string
}
func setupEnvironment(c *cli.Context) (err error) {
+ var config Config
var scopes []string
instanceURL := defaultInstanceURL
@@ -56,14 +70,24 @@
instanceName := basename(instanceURL)
+ if fAuthMethod != "" && authMethods[fAuthMethod] {
+
+ }
+
// Load configuration, will register if none is found
cnf, err = LoadConfig(instanceName)
if err != nil {
// Nothing exist yet
- defName := Config{
- Default: instanceName,
- }
- err = defName.Write()
+ /*
+ defName := Config{
+ Default: instanceName,
+ Auth: "basic",
+ User: "",
+ Password: "",
+ }
+ */
+
+ err = config.Write()
if err != nil {
log.Fatalf("error: can not write config for %s", instanceName)
}
@@ -99,7 +123,12 @@
}
}
+
// Log in to the instance
+ if fAuthMethod == "basic" {
+ err = instance.LoginBasic(fUsername, fPassword)
+ }
+
return err
}
@@ -123,10 +152,10 @@
app.Before = setupEnvironment
app.Flags = []cli.Flag{
- cli.BoolFlag{
- Name: "verbose,v",
- Usage: "verbose mode",
- Destination: &fVerbose,
+ cli.StringFlag{
+ Name: "auth,A",
+ Usage: "authentication mode",
+ Destination: &fAuthMethod,
},
cli.StringFlag{
Name: "instance,I",
@@ -148,6 +177,11 @@
Usage: "user password",
Destination: &fPassword,
},
+ cli.BoolFlag{
+ Name: "verbose,v",
+ Usage: "verbose mode",
+ Destination: &fVerbose,
+ },
}
app.Run(os.Args)
}
--- a/login.go Wed Apr 12 18:28:39 2017 +0200
+++ b/login.go Wed Apr 12 22:26:52 2017 +0200
@@ -14,7 +14,7 @@
TokenType string `json:"token_type"`
}
-func (g *Client) Login(username, password string) error {
+func (g *Client) LoginBasic(username, password string) error {
if username == "" {
return fmt.Errorf("missing username")
}