Skip to content

Commit

Permalink
feat: Found new solution for auth that does not require a server be s…
Browse files Browse the repository at this point in the history
…tarted
  • Loading branch information
whomwah committed Dec 13, 2022
1 parent 25323c3 commit 3a824bd
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 132 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ and double click the `.workflow` file to open and install or update.
By default you access the workflow via the `gh` command.

The first time you use the workflow you will need an access token so the
workflow can speak to github on your behalf. You can do this via the
workflow can speak to Github on your behalf. You can do this via the
`gh > login` command. Pressing enter will take you to an authorisation page on
Github. The permissions are used only by the workflow.
Github. The permissions are required only by the workflow. I'm not evil.

There are a few top level commands and other than that you just start typing a
`repo` or `user` you are interested in. Once you start seeing results, pressing
Expand Down
2 changes: 1 addition & 1 deletion env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const DATA_DIR = `${
}/Library/Application Support/Alfred/Workflow Data/${BUNDLE}`;
const DB_DIR = `${DATA_DIR}/db`;
const DATABASE = `${DB_DIR}/${DB_NAME}`;
const STATE = "robotsonghalfredworkflow";
const STATE = "robotsonalfredworkflow";
const GITHUB_OAUTH_URL = "https://github.com/login/oauth/authorize";
const GITHUB_CLIENT_ID = "869cbedd6ed52af80986";
const OAUTH_URL =
Expand Down
141 changes: 90 additions & 51 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
<false/>
</dict>
</array>
<key>44FE5B75-00E4-438E-AD4A-DD909B838A4C</key>
<array>
<dict>
<key>destinationuid</key>
<string>82B15CD5-4C50-4DE4-A0FD-6534151A56B0</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>4717FF19-F3EA-437A-9420-23401B9E626B</key>
<array>
<dict>
Expand Down Expand Up @@ -85,6 +98,55 @@
<string>Github</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>2</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>gh</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<false/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Octocat initialising...please wait whilst we prefetch data</string>
<key>script</key>
<string>$(which deno) run --allow-env --allow-write --allow-read --allow-net ${INIT_FILE} filter $argv[1]</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search or type a command</string>
<key>title</key>
<string>gh...</string>
<key>type</key>
<integer>5</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>D826D6D1-5C1A-45D5-8933-7B0BA272293A</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -144,55 +206,6 @@ echo "You are running the latest version (${alfred_workflow_version})"</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>2</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>gh</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<false/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Octocat initialising...please wait whilst we prefetch data</string>
<key>script</key>
<string>$(which deno) run --allow-env --allow-write --allow-read --allow-net ${INIT_FILE} filter $argv[1]</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search or type a command</string>
<key>title</key>
<string>gh...</string>
<key>type</key>
<integer>5</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>D826D6D1-5C1A-45D5-8933-7B0BA272293A</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -269,6 +282,21 @@ echo "You are running the latest version (${alfred_workflow_version})"</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>availableviaurlhandler</key>
<true/>
<key>triggerid</key>
<string>auth</string>
</dict>
<key>type</key>
<string>alfred.workflow.trigger.external</string>
<key>uid</key>
<string>44FE5B75-00E4-438E-AD4A-DD909B838A4C</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string># Github Workflow
Expand Down Expand Up @@ -312,6 +340,17 @@ https://github.com/whomwah/alfred-github-workflow/releases</string>
<key>ypos</key>
<real>130</real>
</dict>
<key>44FE5B75-00E4-438E-AD4A-DD909B838A4C</key>
<dict>
<key>colorindex</key>
<integer>6</integer>
<key>note</key>
<string>Entry point for your Github Auth Token</string>
<key>xpos</key>
<real>50</real>
<key>ypos</key>
<real>450</real>
</dict>
<key>4717FF19-F3EA-437A-9420-23401B9E626B</key>
<dict>
<key>note</key>
Expand All @@ -335,9 +374,9 @@ https://github.com/whomwah/alfred-github-workflow/releases</string>
<key>note</key>
<string>Main script that takes input and returns the items you see</string>
<key>xpos</key>
<real>90</real>
<real>40</real>
<key>ypos</key>
<real>145</real>
<real>100</real>
</dict>
</dict>
<key>userconfigurationconfig</key>
Expand Down
16 changes: 10 additions & 6 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { removeConfig, storeConfig } from "./helpers/config.ts";
import { dbConnect, deleteDatabase } from "./setup.ts";
import { openPath, openUrlInBrowser } from "./helpers/url.ts";
import { log } from "./helpers/log.ts";
import { startServer } from "./server.ts";
import { dirname } from "../deps.ts";

export default async function Action(query: string) {
Expand All @@ -16,18 +15,23 @@ export default async function Action(query: string) {
// We want to generate a new auth token
case action("###login###"): {
await openUrlInBrowser(query.replace("###login###", ""));
await startServer(db, (message: string) => log(message));
break;
}
// We want add our own auth token
case action("###login_with_token###"): {
// There was an issue with the token
case action("@@@error@@@"): {
const message = query.replace("@@@error@@@", "");
log(`Oops! There was a problem: ${message}`);
break;
}
// We want save our auth token
case action("@@@token@@@"): {
storeConfig(
db,
"access_token",
query.replace("###login_with_token###", ""),
query.replace("@@@token@@@", ""),
);
db.close();
log("Added token successfully!");
log("Success! Your token has been saved. Enjoy this Alfred workflow.");
break;
}
// We want to clear the current auth token set
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ export function loginCommands(queryArgs: QueryArgs, builder: BuilderType) {
title: `Login ${token}`,
subtitle: "Save access token",
icon: "login",
arg: `###login_with_token###${token}`,
arg: `@@@token@@@${token}`,
valid,
skipMatch: true,
});

return Promise.all(
Expand Down
15 changes: 0 additions & 15 deletions src/helpers/html.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Deno.test("When we have an empty access token", async (t) => {
assertEquals(items[0].autocomplete, "> login");
assertEquals(
items[0].arg,
"###login###https://github.com/login/oauth/authorize?client_id=869cbedd6ed52af80986&scope=repo,gist&state=robotsonghalfredworkflow",
"###login###https://github.com/login/oauth/authorize?client_id=869cbedd6ed52af80986&scope=repo,gist&state=robotsonalfredworkflow",
);
assertEquals(items[0].icon, { path: "./icons/login.png" });

assertEquals(items[1].title, "Login <access_token>");
assertEquals(items[1].autocomplete, "> login ");
assertEquals(items[1].arg, "###login_with_token###<access_token>");
assertEquals(items[1].arg, "@@@token@@@<access_token>");
assertEquals(items[1].icon, { path: "./icons/login.png" });
});

Expand All @@ -50,7 +50,7 @@ Deno.test("When we have an empty access token", async (t) => {

assertEquals(items[0].title, "Login abc123");
assertEquals(items[0].autocomplete, "> login ");
assertEquals(items[0].arg, "###login_with_token###abc123");
assertEquals(items[0].arg, "@@@token@@@abc123");
assertEquals(items[0].icon, { path: "./icons/login.png" });
});
});
Expand Down
53 changes: 0 additions & 53 deletions src/server.ts

This file was deleted.

0 comments on commit 3a824bd

Please sign in to comment.