@@ -79,9 +79,62 @@ describe('ExpressOAuthServer', function() {
7979 . expect ( 200 )
8080 . end ( done ) ;
8181 } ) ;
82+
83+ it ( 'should cache the authorization token' , function ( done ) {
84+ var token = { user : { } } ;
85+ var model = {
86+ getAccessToken : function ( ) {
87+ return token ;
88+ }
89+ } ;
90+ var oauth = new ExpressOAuthServer ( { model : model } ) ;
91+
92+ app . use ( oauth . authenticate ( ) ) ;
93+
94+ app . use ( function ( req , res , next ) {
95+ res . locals . oauth . token . should . equal ( token ) ;
96+
97+ next ( ) ;
98+ } ) ;
99+
100+ request ( app . listen ( ) )
101+ . get ( '/' )
102+ . set ( 'Authorization' , 'Bearer foobar' )
103+ . end ( done ) ;
104+ } ) ;
82105 } ) ;
83106
84107 describe ( 'authorize()' , function ( ) {
108+ it ( 'should cache the authorization code' , function ( done ) {
109+ var code = { authorizationCode : 123 } ;
110+ var model = {
111+ getAccessToken : function ( ) {
112+ return { user : { } } ;
113+ } ,
114+ getClient : function ( ) {
115+ return { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com' ] } ;
116+ } ,
117+ saveAuthorizationCode : function ( ) {
118+ return code ;
119+ }
120+ } ;
121+ var oauth = new ExpressOAuthServer ( { model : model } ) ;
122+
123+ app . use ( oauth . authorize ( ) ) ;
124+
125+ app . use ( function ( req , res , next ) {
126+ res . locals . oauth . code . should . equal ( code ) ;
127+
128+ next ( ) ;
129+ } ) ;
130+
131+ request ( app . listen ( ) )
132+ . post ( '/?state=foobiz' )
133+ . set ( 'Authorization' , 'Bearer foobar' )
134+ . send ( { client_id : 12345 , response_type : 'code' } )
135+ . end ( done ) ;
136+ } ) ;
137+
85138 it ( 'should return a `location` header with the error' , function ( done ) {
86139 var model = {
87140 getAccessToken : function ( ) {
@@ -143,6 +196,36 @@ describe('ExpressOAuthServer', function() {
143196 } ) ;
144197
145198 describe ( 'token()' , function ( ) {
199+ it ( 'should cache the authorization token' , function ( done ) {
200+ var token = { accessToken : 'foobar' , client : { } , user : { } } ;
201+ var model = {
202+ getClient : function ( ) {
203+ return { grants : [ 'password' ] } ;
204+ } ,
205+ getUser : function ( ) {
206+ return { } ;
207+ } ,
208+ saveToken : function ( ) {
209+ return token ;
210+ }
211+ } ;
212+ var oauth = new ExpressOAuthServer ( { model : model } ) ;
213+
214+ app . use ( oauth . token ( ) ) ;
215+
216+ app . use ( function ( req , res , next ) {
217+ res . locals . oauth . token . should . equal ( token ) ;
218+
219+ next ( ) ;
220+ } ) ;
221+
222+ request ( app . listen ( ) )
223+ . post ( '/' )
224+ . send ( 'client_id=foo&client_secret=bar&grant_type=password&username=qux&password=biz' )
225+ . expect ( { access_token : 'foobar' , token_type : 'bearer' } )
226+ . end ( done ) ;
227+ } ) ;
228+
146229 it ( 'should return an `access_token`' , function ( done ) {
147230 var model = {
148231 getClient : function ( ) {
0 commit comments