Total Lines | 69 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package oauth |
||
2 | |||
3 | import ( |
||
4 | "github.com/memnix/memnix-rest/pkg/json" |
||
5 | ) |
||
6 | |||
7 | const ( |
||
8 | // RequestFailed is the error message when a request fails. |
||
9 | RequestFailed = "request failed" |
||
10 | // ResponseFailed is the error message when a response fails. |
||
11 | ResponseFailed = "response failed" |
||
12 | ) |
||
13 | |||
14 | var jsonHelper = json.NewJSON(&json.NativeJSON{}) |
||
15 | |||
16 | type GlobalConfig struct { |
||
17 | CallbackURL string |
||
18 | FrontendURL string |
||
19 | } |
||
20 | |||
21 | var ( |
||
22 | githubConfig GithubConfig |
||
23 | discordConfig DiscordConfig |
||
24 | oauthConfig GlobalConfig |
||
25 | ) |
||
26 | |||
27 | type GithubConfig struct { |
||
28 | ClientID string |
||
29 | ClientSecret string |
||
30 | } |
||
31 | |||
32 | type DiscordConfig struct { |
||
33 | ClientID string |
||
34 | ClientSecret string |
||
35 | URL string |
||
36 | } |
||
37 | |||
38 | func GetGithubClientID() string { |
||
39 | return githubConfig.ClientID |
||
40 | } |
||
41 | |||
42 | func GetCallbackURL() string { |
||
43 | return oauthConfig.CallbackURL |
||
44 | } |
||
45 | |||
46 | func GetFrontendURL() string { |
||
47 | return oauthConfig.FrontendURL |
||
48 | } |
||
49 | |||
50 | func GetDiscordURL() string { |
||
51 | return discordConfig.URL |
||
52 | } |
||
53 | |||
54 | func SetJSONHelper(helper json.Helper) { |
||
55 | jsonHelper = json.NewJSON(helper) |
||
56 | } |
||
57 | |||
58 | // InitGithub initializes the Github oauth configuration. |
||
59 | func InitGithub(config GithubConfig) { |
||
60 | githubConfig = config |
||
61 | } |
||
62 | |||
63 | // InitDiscord initializes the Discord oauth configuration. |
||
64 | func InitDiscord(config DiscordConfig) { |
||
65 | discordConfig = config |
||
66 | } |
||
67 | |||
68 | func SetOauthConfig(config GlobalConfig) { |
||
69 | oauthConfig = config |
||
70 | } |
||
71 |