| ... | @@ -0,0 +1,157 @@ |
| 1 | // https://oauth.net/2/ |
| 2 | // |
| 3 | const std = @import("std"); |
| 4 | const string = []const u8; |
| 5 | |
| 6 | pub 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 | |
| 19 | pub const Client = struct { |
| 20 | provider: Provider, |
| 21 | id: string, |
| 22 | secret: string, |
| 23 | }; |
| 24 | |
| 25 | pub 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 | }; |