@@ -55,7 +55,7 @@ public void buildAuthorizeUrl_v1() {
5555 .build ();
5656 App app = new App (config );
5757 String url = app .buildAuthorizeUrl ("state-value" );
58- assertEquals ("https://slack.com/oauth/authorize?client_id=123&scope=commands,chat:write &state=state-value" , url );
58+ assertEquals ("https://slack.com/oauth/authorize?client_id=123&scope=commands%2Cchat%3Awrite &state=state-value" , url );
5959 }
6060
6161 @ Test
@@ -69,7 +69,7 @@ public void buildAuthorizeUrl_v1_with_redirect_uri() {
6969 .build ();
7070 App app = new App (config );
7171 String url = app .buildAuthorizeUrl ("state-value" );
72- assertEquals ("https://slack.com/oauth/authorize?client_id=123&scope=commands,chat:write &state=state-value&redirect_uri=https%3A%2F%2Fmy.app%2Foauth%2Fcallback" , url );
72+ assertEquals ("https://slack.com/oauth/authorize?client_id=123&scope=commands%2Cchat%3Awrite &state=state-value&redirect_uri=https%3A%2F%2Fmy.app%2Foauth%2Fcallback" , url );
7373 }
7474
7575 @ Test
@@ -82,7 +82,7 @@ public void buildAuthorizeUrl_v2() {
8282 .build ();
8383 App app = new App (config );
8484 String url = app .buildAuthorizeUrl ("state-value" );
85- assertEquals ("https://slack.com/oauth/v2/authorize?client_id=123&scope=commands,chat:write &user_scope=search:read &state=state-value" , url );
85+ assertEquals ("https://slack.com/oauth/v2/authorize?client_id=123&scope=commands%2Cchat%3Awrite &user_scope=search%3Aread &state=state-value" , url );
8686 }
8787
8888 @ Test
@@ -96,7 +96,7 @@ public void buildAuthorizeUrl_v2_with_redirect_uri() {
9696 .build ();
9797 App app = new App (config );
9898 String url = app .buildAuthorizeUrl ("state-value" );
99- assertEquals ("https://slack.com/oauth/v2/authorize?client_id=123&scope=commands,chat:write &user_scope=search:read &state=state-value&redirect_uri=https%3A%2F%2Fmy.app%2Foauth%2Fcallback" , url );
99+ assertEquals ("https://slack.com/oauth/v2/authorize?client_id=123&scope=commands%2Cchat%3Awrite &user_scope=search%3Aread &state=state-value&redirect_uri=https%3A%2F%2Fmy.app%2Foauth%2Fcallback" , url );
100100 }
101101
102102 @ Test
@@ -106,6 +106,114 @@ public void buildAuthorizeUrl_null() {
106106 assertNull (url );
107107 }
108108
109+ @ Test
110+ public void buildAuthorizeUrl_bot_scope () {
111+ App app = new App (AppConfig .builder ()
112+ .signingSecret ("secret" )
113+ .clientId ("111.222" )
114+ .clientSecret ("secret" )
115+ .scope ("commands,chat:write" )
116+ .build ());
117+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
118+ assertEquals ("https://slack.com/oauth/v2/authorize" +
119+ "?client_id=111.222&scope=commands%2Cchat%3Awrite&user_scope=&state=state-value" , generatedUrl );
120+ }
121+
122+ @ Test
123+ public void buildAuthorizeUrl_bot_and_user_scope () {
124+ App app = new App (AppConfig .builder ()
125+ .signingSecret ("secret" )
126+ .clientId ("111.222" )
127+ .clientSecret ("secret" )
128+ .scope ("commands,chat:write" )
129+ .userScope ("search:read,chat:write" )
130+ .build ());
131+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
132+ assertEquals ("https://slack.com/oauth/v2/authorize" +
133+ "?client_id=111.222&scope=commands%2Cchat%3Awrite&user_scope=search%3Aread%2Cchat%3Awrite&state=state-value" , generatedUrl );
134+ }
135+
136+ @ Test
137+ public void buildAuthorizeUrl_user_scope () {
138+ App app = new App (AppConfig .builder ()
139+ .signingSecret ("secret" )
140+ .clientId ("111.222" )
141+ .clientSecret ("secret" )
142+ .userScope ("search:read,chat:write" )
143+ .build ());
144+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
145+ assertEquals ("https://slack.com/oauth/v2/authorize?client_id=111.222&scope=&user_scope=search%3Aread%2Cchat%3Awrite&state=state-value" , generatedUrl );
146+ }
147+
148+ @ Test
149+ public void buildAuthorizeUrl_OpenID_Connect () {
150+ App app = new App (AppConfig .builder ()
151+ .openIDConnectEnabled (true )
152+ .signingSecret ("secret" )
153+ .clientId ("111.222" )
154+ .userScope ("openid,email" )
155+ .build ());
156+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
157+ assertEquals ("https://slack.com/openid/connect/authorize?client_id=111.222&response_type=code&scope=openid%2Cemail&state=state-value" , generatedUrl );
158+ }
159+
160+ @ Test
161+ public void buildAuthorizeUrl_OpenID_Connect_invalid () {
162+ App app = new App (AppConfig .builder ()
163+ .openIDConnectEnabled (true )
164+ .signingSecret ("secret" )
165+ .clientId ("111.222" )
166+ .scope ("openid,email" )
167+ .build ());
168+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
169+ assertNull (generatedUrl );
170+ }
171+
172+ @ Test
173+ public void buildAuthorizeUrl_bot_scope_classic () {
174+ App app = new App (AppConfig .builder ()
175+ .classicAppPermissionsEnabled (true )
176+ .signingSecret ("secret" )
177+ .clientId ("111.222" )
178+ .clientSecret ("secret" )
179+ .scope ("commands,chat:write" )
180+ .build ());
181+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
182+ // use_scope= does not exist in the Slack OAuth v1
183+ assertEquals ("https://slack.com/oauth/authorize" +
184+ "?client_id=111.222&scope=commands%2Cchat%3Awrite&state=state-value" , generatedUrl );
185+ }
186+
187+ @ Test
188+ public void buildAuthorizeUrl_bot_and_user_scope_classic () {
189+ App app = new App (AppConfig .builder ()
190+ .classicAppPermissionsEnabled (true )
191+ .signingSecret ("secret" )
192+ .clientId ("111.222" )
193+ .clientSecret ("secret" )
194+ .scope ("commands,chat:write" )
195+ .userScope ("search:read,chat:write" )
196+ .build ());
197+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
198+ // use_scope= does not exist in the Slack OAuth v1
199+ assertEquals ("https://slack.com/oauth/authorize" +
200+ "?client_id=111.222&scope=commands%2Cchat%3Awrite&state=state-value" , generatedUrl );
201+ }
202+
203+ @ Test
204+ public void buildAuthorizeUrl_user_scope_classic () {
205+ App app = new App (AppConfig .builder ()
206+ .classicAppPermissionsEnabled (true )
207+ .signingSecret ("secret" )
208+ .clientId ("111.222" )
209+ .clientSecret ("secret" )
210+ .userScope ("search:read,chat:write" )
211+ .build ());
212+ String generatedUrl = app .buildAuthorizeUrl ("state-value" );
213+ // use_scope= does not exist in the Slack OAuth v1
214+ assertEquals ("https://slack.com/oauth/authorize?client_id=111.222&scope=&state=state-value" , generatedUrl );
215+ }
216+
109217 @ Test
110218 public void status () {
111219 App app = new App (AppConfig .builder ()
0 commit comments