authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-10 19:27:33 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-10 19:27:33 -07:00
log7bd7875f76508181ed3cc4e55563d34507d2cec1
tree63884dca6a1ba2bdf66ee2609224a72e651d2314
parent6ea8c2bcf5dca7965b1bd38433ee6f1973950982

initial code commit


6 files changed, 201 insertions(+), 0 deletions(-)

.gitignore created+3
...@@ -0,0 +1,3 @@
1zig-*
2.zigmod
3deps.zig
build.zig created+29
...@@ -0,0 +1,29 @@
1const std = @import("std");
2const deps = @import("./deps.zig");
3
4pub fn build(b: *std.build.Builder) void {
5 // Standard target options allows the person running `zig build` to choose
6 // what target to build for. Here we do not override the defaults, which
7 // means any target is allowed, and the default is native. Other options
8 // for restricting supported target set are available.
9 const target = b.standardTargetOptions(.{});
10
11 // Standard release options allow the person running `zig build` to select
12 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
13 const mode = b.standardReleaseOptions();
14
15 const exe = b.addExecutable("zig-oauth2", "src/main.zig");
16 exe.setTarget(target);
17 exe.setBuildMode(mode);
18 deps.addAllTo(exe);
19 exe.install();
20
21 const run_cmd = exe.run();
22 run_cmd.step.dependOn(b.getInstallStep());
23 if (b.args) |args| {
24 run_cmd.addArgs(args);
25 }
26
27 const run_step = b.step("run", "Run the app");
28 run_step.dependOn(&run_cmd.step);
29}
src/lib.zig created+157
...@@ -0,0 +1,157 @@
1// https://oauth.net/2/
2//
3const std = @import("std");
4const string = []const u8;
5
6pub const Provider = struct {
7 id: string,
8 authorize_url: string,
9 token_url: string,
10 me_url: string,
11 scope: string = "",
12 name_prop: string,
13 name_prefix: string = "",
14 id_prop: string = "id",
15 logo: string,
16 color: string,
17};
18
19pub const Client = struct {
20 provider: Provider,
21 id: string,
22 secret: string,
23};
24
25pub const providers = struct {
26 fn icon_url(comptime name: string) string {
27 return "https://unpkg.com/simple-icons@" ++ "5.13.0" ++ "/icons/" ++ name ++ ".svg";
28 }
29
30 pub var amazon = Provider{
31 .id = "amazon",
32 .authorize_url = "https://www.amazon.com/ap/oa",
33 .token_url = "https://api.amazon.com/auth/o2/token",
34 .me_url = "https://api.amazon.com/user/profile",
35 .scope = "profile",
36 .name_prop = "name",
37 .id_prop = "user_id",
38 .logo = icon_url("amazon"),
39 .color = "#FF9900",
40 };
41 pub var battle_net = Provider{
42 .id = "battle.net",
43 .authorize_url = "https://us.battle.net/oauth/authorize",
44 .token_url = "https://us.battle.net/oauth/token",
45 .me_url = "https://us.battle.net/oauth/userinfo",
46 .scope = "openid",
47 .name_prop = "battletag",
48 .logo = icon_url("battle-dot-net"),
49 .color = "#00AEFF",
50 };
51 pub var discord = Provider{
52 .id = "discord",
53 .authorize_url = "https://discordapp.com/api/oauth2/authorize",
54 .token_url = "https://discordapp.com/api/oauth2/token",
55 .me_url = "https://discordapp.com/api/users/@me",
56 .scope = "identify",
57 .name_prop = "username",
58 .name_prefix = "@",
59 .logo = icon_url("discord"),
60 .color = "#7289DA",
61 };
62 pub var facebook = Provider{
63 .id = "facebook",
64 .authorize_url = "https://graph.facebook.com/oauth/authorize",
65 .token_url = "https://graph.facebook.com/oauth/access_token",
66 .me_url = "https://graph.facebook.com/me",
67 .name_prop = "name",
68 .logo = icon_url("facebook"),
69 .color = "#1877F2",
70 };
71 pub var github = Provider{
72 .id = "github",
73 .authorize_url = "https://github.com/login/oauth/authorize",
74 .token_url = "https://github.com/login/oauth/access_token",
75 .me_url = "https://api.github.com/user",
76 .scope = "read:user",
77 .name_prop = "login",
78 .name_prefix = "@",
79 .logo = icon_url("github"),
80 .color = "#181717",
81 };
82 pub var google = Provider{
83 .id = "google",
84 .authorize_url = "https://accounts.google.com/o/oauth2/v2/auth",
85 .token_url = "https://www.googleapis.com/oauth2/v4/token",
86 .me_url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
87 .scope = "profile",
88 .name_prop = "name",
89 .logo = icon_url("google"),
90 .color = "#4285F4",
91 };
92 pub var microsoft = Provider{
93 .id = "microsoft",
94 .authorize_url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
95 .token_url = "https://login.microsoftonline.com/common/oauth2/v2.0/token",
96 .me_url = "https://graph.microsoft.com/v1.0/me/",
97 .scope = "https://graph.microsoft.com/user.read",
98 .name_prop = "displayName",
99 .logo = icon_url("microsoft"),
100 .color = "#666666",
101 };
102 pub var reddit = Provider{
103 .id = "reddit",
104 .authorize_url = "https://old.reddit.com/api/v1/authorize",
105 .token_url = "https://old.reddit.com/api/v1/access_token",
106 .me_url = "https://oauth.reddit.com/api/v1/me",
107 .scope = "identity",
108 .name_prop = "name",
109 .name_prefix = "u/",
110 .logo = icon_url("reddit"),
111 .color = "#FF4500",
112 };
113
114 pub var _gitea = Provider{
115 .id = "_gitea",
116 .authorize_url = "https://{domain}/login/oauth/authorize",
117 .token_url = "https://{domain}/login/oauth/access_token",
118 .me_url = "https://{domain}/api/v1/user",
119 .name_prop = "username",
120 .name_prefix = "@",
121 .logo = icon_url("gitea"),
122 .color = "#609926",
123 };
124 pub var _gitlab = Provider{
125 .id = "_gitlab",
126 .authorize_url = "https://{domain}/oauth/authorize",
127 .token_url = "https://{domain}/oauth/token",
128 .me_url = "https://{domain}/api/v4/user",
129 .scope = "read_user",
130 .name_prop = "username",
131 .name_prefix = "@",
132 .logo = icon_url("gitlab"),
133 .color = "#FCA121",
134 };
135 pub var _mastodon = Provider{
136 .id = "_mastodon",
137 .authorize_url = "https://{domain}/oauth/authorize",
138 .token_url = "https://{domain}/oauth/token",
139 .me_url = "https://{domain}/api/v1/accounts/verify_credentials",
140 .scope = "read:accounts",
141 .name_prop = "username",
142 .name_prefix = "@",
143 .logo = icon_url("mastodon"),
144 .color = "#3088D4",
145 };
146 pub var _pleroma = Provider{
147 .id = "_pleroma",
148 .authorize_url = "https://{domain}/oauth/authorize",
149 .token_url = "https://{domain}/oauth/token",
150 .me_url = "https://{domain}/api/v1/accounts/verify_credentials",
151 .scope = "read:accounts",
152 .name_prop = "username",
153 .name_prefix = "@",
154 .logo = icon_url("pleroma"),
155 .color = "#FBA457",
156 };
157};
src/main.zig created+5
...@@ -0,0 +1,5 @@
1const std = @import("std");
2
3pub fn main() anyerror!void {
4 std.log.info("All your codebase are belong to us.", .{});
5}
zig.mod created+6
...@@ -0,0 +1,6 @@
1id: raz0lqnollhuhz5bq5n57pbo8cwm9l55z475i4ufcpzl57ez
2name: oauth2
3main: src/lib.zig
4license: MIT
5description: HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application
6dependencies:
zigmod.lock created+1
...@@ -0,0 +1 @@
12