@@ -135,6 +135,11 @@ public async Task TestGetAuthorizationUri()
135135 bool [ ] disableSignups = new [ ] { false , true } ;
136136 string [ ] requireRoles = new [ ] { "" , "role" } ;
137137 bool [ ] forceReauthentications = new [ ] { false , true } ;
138+ List < String [ ] > scopes = new List < String [ ] > ( ) ;
139+ scopes . Add ( null ) ;
140+ scopes . Add ( new String [ ] { "files.metadata.read" , "files.content.read" } ) ;
141+ IncludeGrantedScopes [ ] includeGrantedScopes = new [ ] { IncludeGrantedScopes . None , IncludeGrantedScopes . User , IncludeGrantedScopes . Team } ;
142+
138143 TokenAccessType [ ] tokenAccessTypes = new [ ]
139144 { TokenAccessType . Legacy , TokenAccessType . Offline , TokenAccessType . Online } ;
140145 foreach ( string redirectUri in redirectUris )
@@ -151,76 +156,101 @@ public async Task TestGetAuthorizationUri()
151156 {
152157 foreach ( var tokenAccessType in tokenAccessTypes )
153158 {
154- var authUri = DropboxOAuth2Helper . GetAuthorizeUri ( OAuthResponseType . Code ,
155- clientId , redirectUri , state , forceReapprove , disableSignup ,
156- requireRole , forceReauthentication , tokenAccessType ) . ToString ( ) ;
157-
158- Assert . IsTrue ( authUri . StartsWith ( "https://www.dropbox.com/oauth2/authorize" ) ) ;
159- Assert . IsTrue ( authUri . Contains ( "response_type=code" ) ) ;
160- Assert . IsTrue ( authUri . Contains ( "client_id=" + clientId ) ) ;
161-
162- if ( String . IsNullOrWhiteSpace ( state ) )
163- {
164- Assert . IsFalse ( authUri . Contains ( "&state=" ) ) ;
165- }
166- else
167- {
168- Assert . IsTrue ( authUri . Contains ( "&state=" + state ) ) ;
169- }
170-
171- if ( String . IsNullOrWhiteSpace ( redirectUri ) )
172- {
173- Assert . IsFalse ( authUri . Contains ( "&redirect_uri=" ) ) ;
174- }
175- else
176- {
177- Assert . IsTrue ( authUri . Contains ( "&redirect_uri=" + Uri . EscapeDataString ( redirectUri ) ) ) ;
178- }
179-
180- if ( forceReapprove )
181- {
182- Assert . IsTrue ( authUri . Contains ( "&force_reapprove=true" ) ) ;
183- }
184- else
185- {
186- Assert . IsFalse ( authUri . Contains ( "&force_reapprove=" ) ) ;
187- }
188-
189- if ( disableSignup )
159+ foreach ( var scope in scopes )
190160 {
191- Assert . IsTrue ( authUri . Contains ( "&disable_signup=true" ) ) ;
192- }
193- else
194- {
195- Assert . IsFalse ( authUri . Contains ( "&disable_signup=" ) ) ;
196- }
197-
198- if ( String . IsNullOrWhiteSpace ( requireRole ) )
199- {
200- Assert . IsFalse ( authUri . Contains ( "&require_role=" ) ) ;
201- }
202- else
203- {
204- Assert . IsTrue ( authUri . Contains ( "&require_role=" + requireRole ) ) ;
205- }
206-
207- if ( forceReauthentication )
208- {
209- Assert . IsTrue ( authUri . Contains ( "&force_reauthentication=true" ) ) ;
210- }
211- else
212- {
213- Assert . IsFalse ( authUri . Contains ( "&force_reauthentication=" ) ) ;
214- }
215-
216- if ( tokenAccessType != TokenAccessType . Legacy )
217- {
218- Assert . IsTrue ( authUri . Contains ( "&token_access_type=" +
219- tokenAccessType . ToString ( ) . ToLower ( ) ) ) ;
220- }
221- else
222- {
223- Assert . IsFalse ( authUri . Contains ( "&token_access_type=" ) ) ;
161+ foreach ( var includeGrantedScope in includeGrantedScopes )
162+ {
163+ var authUri = DropboxOAuth2Helper . GetAuthorizeUri ( OAuthResponseType . Code ,
164+ clientId , redirectUri , state , forceReapprove , disableSignup ,
165+ requireRole , forceReauthentication , tokenAccessType , scope , includeGrantedScope ) . ToString ( ) ;
166+
167+ Assert . IsTrue ( authUri . StartsWith ( "https://www.dropbox.com/oauth2/authorize" ) ) ;
168+ Assert . IsTrue ( authUri . Contains ( "response_type=code" ) ) ;
169+ Assert . IsTrue ( authUri . Contains ( "client_id=" + clientId ) ) ;
170+
171+ if ( String . IsNullOrWhiteSpace ( state ) )
172+ {
173+ Assert . IsFalse ( authUri . Contains ( "&state=" ) ) ;
174+ }
175+ else
176+ {
177+ Assert . IsTrue ( authUri . Contains ( "&state=" + state ) ) ;
178+ }
179+
180+ if ( String . IsNullOrWhiteSpace ( redirectUri ) )
181+ {
182+ Assert . IsFalse ( authUri . Contains ( "&redirect_uri=" ) ) ;
183+ }
184+ else
185+ {
186+ Assert . IsTrue ( authUri . Contains ( "&redirect_uri=" + Uri . EscapeDataString ( redirectUri ) ) ) ;
187+ }
188+
189+ if ( forceReapprove )
190+ {
191+ Assert . IsTrue ( authUri . Contains ( "&force_reapprove=true" ) ) ;
192+ }
193+ else
194+ {
195+ Assert . IsFalse ( authUri . Contains ( "&force_reapprove=" ) ) ;
196+ }
197+
198+ if ( disableSignup )
199+ {
200+ Assert . IsTrue ( authUri . Contains ( "&disable_signup=true" ) ) ;
201+ }
202+ else
203+ {
204+ Assert . IsFalse ( authUri . Contains ( "&disable_signup=" ) ) ;
205+ }
206+
207+ if ( String . IsNullOrWhiteSpace ( requireRole ) )
208+ {
209+ Assert . IsFalse ( authUri . Contains ( "&require_role=" ) ) ;
210+ }
211+ else
212+ {
213+ Assert . IsTrue ( authUri . Contains ( "&require_role=" + requireRole ) ) ;
214+ }
215+
216+ if ( forceReauthentication )
217+ {
218+ Assert . IsTrue ( authUri . Contains ( "&force_reauthentication=true" ) ) ;
219+ }
220+ else
221+ {
222+ Assert . IsFalse ( authUri . Contains ( "&force_reauthentication=" ) ) ;
223+ }
224+
225+ if ( tokenAccessType != TokenAccessType . Legacy )
226+ {
227+ Assert . IsTrue ( authUri . Contains ( "&token_access_type=" +
228+ tokenAccessType . ToString ( ) . ToLower ( ) ) ) ;
229+ }
230+ else
231+ {
232+ Assert . IsFalse ( authUri . Contains ( "&token_access_type=" ) ) ;
233+ }
234+
235+ if ( scope != null )
236+ {
237+ Assert . IsTrue ( authUri . Contains ( "&scope=" + String . Join ( " " , scope ) ) ) ;
238+ }
239+ else
240+ {
241+ Assert . IsFalse ( authUri . Contains ( "&scope=" ) ) ;
242+ }
243+
244+ if ( includeGrantedScope != IncludeGrantedScopes . None )
245+ {
246+ Assert . IsTrue ( authUri . Contains ( "&include_granted_scopes=" +
247+ includeGrantedScope . ToString ( ) . ToLower ( ) ) ) ;
248+ }
249+ else
250+ {
251+ Assert . IsFalse ( authUri . Contains ( "&include_granted_scopes=" ) ) ;
252+ }
253+ }
224254 }
225255 }
226256 }
0 commit comments