@@ -15,6 +15,13 @@ import (
15
15
16
16
type AppAccessTokenEndpoint struct {}
17
17
18
+ type AppAccessTokenRequestBody struct {
19
+ ClientID string `json:"client_id"`
20
+ ClientSecret string `json:"client_secret"`
21
+ GrantType string `json:"grant_type"`
22
+ Scope string `json:"scope"`
23
+ }
24
+
18
25
type AppAccessTokenEndpointResposne struct {
19
26
AccessToken string `json:"access_token"`
20
27
RefreshToken string `json:"refresh_token"`
@@ -33,12 +40,37 @@ func (e AppAccessTokenEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request
33
40
return
34
41
}
35
42
36
- clientID := r .URL .Query ().Get ("client_id" )
37
- clientSecret := r .URL .Query ().Get ("client_secret" )
38
- grantType := r .URL .Query ().Get ("grant_type" )
39
- scope := r .URL .Query ().Get ("scope" )
40
- scopes := strings .Split (scope , " " )
41
- if clientID == "" || clientSecret == "" || grantType != "client_credentials" {
43
+ params := AppAccessTokenRequestBody {
44
+ ClientID : r .URL .Query ().Get ("client_id" ),
45
+ ClientSecret : r .URL .Query ().Get ("client_secret" ),
46
+ GrantType : r .URL .Query ().Get ("grant_type" ),
47
+ Scope : r .URL .Query ().Get ("scope" ),
48
+ }
49
+
50
+ if r .Header .Get ("Content-Type" ) == "application/x-www-form-urlencoded" {
51
+ err := r .ParseForm ()
52
+ if err != nil {
53
+ mock_errors .WriteServerError (w , err .Error ())
54
+ return
55
+ }
56
+
57
+ if r .Form .Get ("client_id" ) != "" {
58
+ params .ClientID = r .Form .Get ("client_id" )
59
+ }
60
+ if r .Form .Get ("client_secret" ) != "" {
61
+ params .ClientSecret = r .Form .Get ("client_secret" )
62
+ }
63
+ if r .Form .Get ("grant_type" ) != "" {
64
+ params .GrantType = r .Form .Get ("grant_type" )
65
+ }
66
+ if r .Form .Get ("scope" ) != "" {
67
+ params .Scope = r .Form .Get ("scope" )
68
+ }
69
+ }
70
+
71
+ scopes := strings .Split (params .Scope , " " )
72
+
73
+ if params .ClientID == "" || params .ClientSecret == "" || params .GrantType != "client_credentials" {
42
74
w .WriteHeader (http .StatusBadRequest )
43
75
return
44
76
}
@@ -55,7 +87,7 @@ func (e AppAccessTokenEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request
55
87
return
56
88
}
57
89
58
- res , err := db .NewQuery (r , 10 ).GetAuthenticationClient (database.AuthenticationClient {ID : clientID , Secret : clientSecret })
90
+ res , err := db .NewQuery (r , 10 ).GetAuthenticationClient (database.AuthenticationClient {ID : params . ClientID , Secret : params . ClientSecret })
59
91
if err != nil {
60
92
mock_errors .WriteServerError (w , err .Error ())
61
93
return
0 commit comments