| ... | ... | @@ -130,20 +130,20 @@ pub const providers = struct { |
| 130 | 130 | |
| 131 | 131 | pub const dynamic_providers = struct { |
| 132 | 132 | pub const _gitea = Provider{ |
| 133 | | .id = "_gitea", |
| 134 | | .authorize_url = "https://{domain}/login/oauth/authorize", |
| 135 | | .token_url = "https://{domain}/login/oauth/access_token", |
| 136 | | .me_url = "https://{domain}/api/v1/user", |
| 133 | .id = "gitea", |
| 134 | .authorize_url = "https://{[domain]s}/login/oauth/authorize", |
| 135 | .token_url = "https://{[domain]s}/login/oauth/access_token", |
| 136 | .me_url = "https://{[domain]s}/api/v1/user", |
| 137 | 137 | .name_prop = "username", |
| 138 | 138 | .name_prefix = "@", |
| 139 | 139 | .logo = icon_url("gitea"), |
| 140 | 140 | .color = "#609926", |
| 141 | 141 | }; |
| 142 | 142 | pub const _gitlab = Provider{ |
| 143 | | .id = "_gitlab", |
| 144 | | .authorize_url = "https://{domain}/oauth/authorize", |
| 145 | | .token_url = "https://{domain}/oauth/token", |
| 146 | | .me_url = "https://{domain}/api/v4/user", |
| 143 | .id = "gitlab", |
| 144 | .authorize_url = "https://{[domain]s}/oauth/authorize", |
| 145 | .token_url = "https://{[domain]s}/oauth/token", |
| 146 | .me_url = "https://{[domain]s}/api/v4/user", |
| 147 | 147 | .scope = "read_user", |
| 148 | 148 | .name_prop = "username", |
| 149 | 149 | .name_prefix = "@", |
| ... | ... | @@ -151,10 +151,10 @@ pub const dynamic_providers = struct { |
| 151 | 151 | .color = "#FCA121", |
| 152 | 152 | }; |
| 153 | 153 | pub const _mastodon = Provider{ |
| 154 | | .id = "_mastodon", |
| 155 | | .authorize_url = "https://{domain}/oauth/authorize", |
| 156 | | .token_url = "https://{domain}/oauth/token", |
| 157 | | .me_url = "https://{domain}/api/v1/accounts/verify_credentials", |
| 154 | .id = "mastodon", |
| 155 | .authorize_url = "https://{[domain]s}/oauth/authorize", |
| 156 | .token_url = "https://{[domain]s}/oauth/token", |
| 157 | .me_url = "https://{[domain]s}/api/v1/accounts/verify_credentials", |
| 158 | 158 | .scope = "read:accounts", |
| 159 | 159 | .name_prop = "username", |
| 160 | 160 | .name_prefix = "@", |
| ... | ... | @@ -162,10 +162,10 @@ pub const dynamic_providers = struct { |
| 162 | 162 | .color = "#3088D4", |
| 163 | 163 | }; |
| 164 | 164 | pub const _pleroma = Provider{ |
| 165 | | .id = "_pleroma", |
| 166 | | .authorize_url = "https://{domain}/oauth/authorize", |
| 167 | | .token_url = "https://{domain}/oauth/token", |
| 168 | | .me_url = "https://{domain}/api/v1/accounts/verify_credentials", |
| 165 | .id = "pleroma", |
| 166 | .authorize_url = "https://{[domain]s}/oauth/authorize", |
| 167 | .token_url = "https://{[domain]s}/oauth/token", |
| 168 | .me_url = "https://{[domain]s}/api/v1/accounts/verify_credentials", |
| 169 | 169 | .scope = "read:accounts", |
| 170 | 170 | .name_prop = "username", |
| 171 | 171 | .name_prefix = "@", |
| ... | ... | @@ -174,13 +174,34 @@ pub const dynamic_providers = struct { |
| 174 | 174 | }; |
| 175 | 175 | }; |
| 176 | 176 | |
| 177 | | pub fn providerById(name: string) ?Provider { |
| 177 | pub fn providerById(alloc: std.mem.Allocator, name: string) !?Provider { |
| 178 | 178 | inline for (std.meta.declarations(providers)) |item| { |
| 179 | 179 | const p = @field(providers, item.name); |
| 180 | 180 | if (std.mem.eql(u8, p.id, name)) { |
| 181 | 181 | return p; |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | const c_ind = std.mem.indexOfScalar(u8, name, ',') orelse return null; |
| 185 | const p_id = name[0..c_ind]; |
| 186 | const domain = name[c_ind + 1 ..]; |
| 187 | const args = .{ .domain = domain }; |
| 188 | inline for (std.meta.declarations(dynamic_providers)) |item| { |
| 189 | const didp = @field(dynamic_providers, item.name); |
| 190 | if (std.mem.eql(u8, didp.id, p_id)) { |
| 191 | return Provider{ |
| 192 | .id = name, |
| 193 | .authorize_url = try std.fmt.allocPrint(alloc, didp.authorize_url, args), |
| 194 | .token_url = try std.fmt.allocPrint(alloc, didp.token_url, args), |
| 195 | .me_url = try std.fmt.allocPrint(alloc, didp.me_url, args), |
| 196 | .scope = didp.scope, |
| 197 | .name_prop = didp.name_prop, |
| 198 | .name_prefix = didp.name_prefix, |
| 199 | .id_prop = didp.id_prop, |
| 200 | .logo = didp.logo, |
| 201 | .color = didp.color, |
| 202 | }; |
| 203 | } |
| 204 | } |
| 184 | 205 | return null; |
| 185 | 206 | } |
| 186 | 207 | |