-
Notifications
You must be signed in to change notification settings - Fork 0
/
oAuth_main.go
31 lines (21 loc) · 1008 Bytes
/
oAuth_main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"net/http"
"github.com/your-username/your-project-name/auth"
)
/*
When a user accesses the /auth endpoint, the OAuthAuth function will be called, which creates an OAuthConfig struct, using the provided ClientID, ClientSecret, TokenURL and Scopes values, then it uses this config to get an access token from the OAuth2 provider.
It's important to note that you should replace the placeholder values in the example above with the actual values that correspond to your OAuth2 provider (e.g. client_id and client_secret). Also, you should replace the token URL with the URL provided by your OAuth2 provider.
*/
func main() {
http.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
config := &auth.OAuthConfig{
ClientID: "your_client_id",
ClientSecret: "your_client_secret",
TokenURL: "https://your-provider.com/token",
Scopes: []string{"scope1", "scope2"},
}
auth.OAuthAuth(w, r, config)
})
http.ListenAndServe(":8080", nil)
}