@@ -91,16 +91,60 @@ describe('OAuth2Server.token()', function() {
91
91
. send ( { grant_type : 'password' } )
92
92
. expect ( / i n v a l i d o r m i s s i n g c l i e n t _ i d p a r a m e t e r / i, 400 , done ) ;
93
93
} ) ;
94
+
95
+ it ( 'should extract credentials from body' , function ( done ) {
96
+ var app = bootstrap ( {
97
+ model : {
98
+ getClient : function ( id , secret , callback ) {
99
+ try {
100
+ id . should . equal ( 'thom' ) ;
101
+ secret . should . equal ( 'nightworld' ) ;
102
+ callback ( false , false ) ;
103
+ } catch ( e ) {
104
+ return done ( e ) ;
105
+ }
106
+ }
107
+ } ,
108
+ grants : [ 'password' ]
109
+ } ) ;
110
+
111
+ request ( app )
112
+ . post ( '/oauth/token' )
113
+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' )
114
+ . send ( { grant_type : 'password' , client_id : 'thom' , client_secret : 'nightworld' } )
115
+ . expect ( 400 , done ) ;
116
+ } ) ;
117
+
118
+ it ( 'should extract credentials from header (Basic)' , function ( done ) {
119
+ var app = bootstrap ( {
120
+ model : {
121
+ getClient : function ( id , secret , callback ) {
122
+ try {
123
+ id . should . equal ( 'thom' ) ;
124
+ secret . should . equal ( 'nightworld' ) ;
125
+ callback ( false , false ) ;
126
+ } catch ( e ) {
127
+ return done ( e ) ;
128
+ }
129
+ }
130
+ } ,
131
+ grants : [ 'password' ]
132
+ } ) ;
133
+
134
+ request ( app )
135
+ . post ( '/oauth/token' )
136
+ . set ( 'Authorization' , 'Basic dGhvbTpuaWdodHdvcmxkCg==' )
137
+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' )
138
+ . send ( { grant_type : 'password' } )
139
+ . expect ( 400 , done ) ;
140
+ } ) ;
94
141
} ) ;
95
142
96
143
describe ( 'check client credentials against model' , function ( ) {
97
144
it ( 'should detect invalid client' , function ( done ) {
98
145
var app = bootstrap ( {
99
146
model : {
100
147
getClient : function ( id , secret , callback ) {
101
- id . should . equal ( 'thom' ) ;
102
- secret . should . equal ( 'nightworld' ) ;
103
-
104
148
callback ( false , false ) ; // Fake invalid
105
149
}
106
150
} ,
0 commit comments