@@ -765,6 +765,8 @@ func (s *Server) handleToken(w http.ResponseWriter, r *http.Request) {
765765 s .handleRefreshToken (w , r , client )
766766 case grantTypePassword :
767767 s .handlePasswordGrant (w , r , client )
768+ case grantTypeClientCredentials :
769+ s .handleClientCredentialsGrant (w , r , client )
768770 default :
769771 s .tokenErrHelper (w , errInvalidGrant , "" , http .StatusBadRequest )
770772 }
@@ -1169,6 +1171,29 @@ func (s *Server) handleUserInfo(w http.ResponseWriter, r *http.Request) {
11691171 w .Write (claims )
11701172}
11711173
1174+ func (s * Server ) handleClientCredentialsGrant (w http.ResponseWriter , r * http.Request , client storage.Client ) {
1175+ if err := r .ParseForm (); err != nil {
1176+ s .tokenErrHelper (w , errInvalidRequest , "Couldn't parse data" , http .StatusBadRequest )
1177+ return
1178+ }
1179+ q := r .Form
1180+
1181+ nonce := q .Get ("nonce" )
1182+ scopes := strings .Fields (q .Get ("scope" ))
1183+
1184+ claims := storage.Claims {UserID : client .ID }
1185+
1186+ accessToken := storage .NewID ()
1187+ idToken , expiry , err := s .newIDToken (client .ID , claims , scopes , nonce , accessToken , "client" )
1188+ if err != nil {
1189+ s .tokenErrHelper (w , errServerError , fmt .Sprintf ("failed to create ID token: %v" , err ), http .StatusInternalServerError )
1190+ return
1191+ }
1192+
1193+ resp := s .toAccessTokenResponse (idToken , accessToken , "" , expiry )
1194+ s .writeAccessToken (w , resp )
1195+ }
1196+
11721197func (s * Server ) handlePasswordGrant (w http.ResponseWriter , r * http.Request , client storage.Client ) {
11731198 // Parse the fields
11741199 if err := r .ParseForm (); err != nil {
0 commit comments