@@ -107,23 +107,16 @@ function OAuthProvider() {
107107 * Retrieves the `access_token` and stores the `response.data` on cookies
108108 * using the `OAuthToken`.
109109 *
110- * @param {object } user - Object with `username` and `password` properties .
111- * @param {object } config - Optional configuration object sent to `POST` .
110+ * @param {object } data - Request content, e.g., `username` and `password`.
111+ * @param {object } options - Optional configuration.
112112 * @return {promise } A response promise.
113113 */
114114
115- getAccessToken ( user , options ) {
116- // Check if `user` has required properties.
117- if ( ! user || ! user . username || ! user . password ) {
118- throw new Error ( '`user` must be an object with `username` and `password` properties.' ) ;
119- }
120-
121- var data = {
115+ getAccessToken ( data , options ) {
116+ data = angular . extend ( {
122117 client_id : config . clientId ,
123- grant_type : 'password' ,
124- username : user . username ,
125- password : user . password
126- } ;
118+ grant_type : 'password'
119+ } , data ) ;
127120
128121 if ( null !== config . clientSecret ) {
129122 data . client_secret = config . clientSecret ;
@@ -132,7 +125,10 @@ function OAuthProvider() {
132125 data = queryString . stringify ( data ) ;
133126
134127 options = angular . extend ( {
135- headers : { 'Content-Type' : 'application/x-www-form-urlencoded' }
128+ headers : {
129+ 'Authorization' : undefined ,
130+ 'Content-Type' : 'application/x-www-form-urlencoded'
131+ }
136132 } , options ) ;
137133
138134 return $http . post ( `${ config . baseUrl } ${ config . grantPath } ` , data , options ) . then ( ( response ) => {
@@ -146,28 +142,30 @@ function OAuthProvider() {
146142 * Retrieves the `refresh_token` and stores the `response.data` on cookies
147143 * using the `OAuthToken`.
148144 *
145+ * @param {object } data - Request content.
146+ * @param {object } options - Optional configuration.
149147 * @return {promise } A response promise.
150148 */
151149
152- getRefreshToken ( ) {
153- var data = {
150+ getRefreshToken ( data , options ) {
151+ data = angular . extend ( {
154152 client_id : config . clientId ,
155153 grant_type : 'refresh_token' ,
156154 refresh_token : OAuthToken . getRefreshToken ( ) ,
157- } ;
155+ } , data ) ;
158156
159157 if ( null !== config . clientSecret ) {
160158 data . client_secret = config . clientSecret ;
161159 }
162160
163161 data = queryString . stringify ( data ) ;
164162
165- var options = {
163+ options = angular . extend ( {
166164 headers : {
167165 'Authorization' : undefined ,
168166 'Content-Type' : 'application/x-www-form-urlencoded'
169167 }
170- } ;
168+ } , options ) ;
171169
172170 return $http . post ( `${ config . baseUrl } ${ config . grantPath } ` , data , options ) . then ( ( response ) => {
173171 OAuthToken . setToken ( response . data ) ;
@@ -180,24 +178,31 @@ function OAuthProvider() {
180178 * Revokes the `token` and removes the stored `token` from cookies
181179 * using the `OAuthToken`.
182180 *
181+ * @param {object } data - Request content.
182+ * @param {object } options - Optional configuration.
183183 * @return {promise } A response promise.
184184 */
185185
186- revokeToken ( ) {
187- var data = {
186+ revokeToken ( data , options ) {
187+ var refreshToken = OAuthToken . getRefreshToken ( ) ;
188+
189+ data = angular . extend ( {
188190 client_id : config . clientId ,
189- token : OAuthToken . getRefreshToken ( ) ? OAuthToken . getRefreshToken ( ) : OAuthToken . getAccessToken ( )
190- } ;
191+ token : refreshToken ? refreshToken : OAuthToken . getAccessToken ( ) ,
192+ token_type_hint : refreshToken ? 'refresh_token' : 'access_token'
193+ } , data ) ;
191194
192195 if ( null !== config . clientSecret ) {
193196 data . client_secret = config . clientSecret ;
194197 }
195198
196199 data = queryString . stringify ( data ) ;
197200
198- var options = {
199- headers : { 'Content-Type' : 'application/x-www-form-urlencoded' }
200- } ;
201+ options = angular . extend ( {
202+ headers : {
203+ 'Content-Type' : 'application/x-www-form-urlencoded'
204+ }
205+ } , options ) ;
201206
202207 return $http . post ( `${ config . baseUrl } ${ config . revokePath } ` , data , options ) . then ( ( response ) => {
203208 OAuthToken . removeToken ( ) ;
0 commit comments