Skip to content

version 1.14.0

Compare
Choose a tag to compare
@seratch seratch released this 13 Nov 02:08
· 1037 commits to main since this release

New Features

OAuth flow persistence callbacks

In the past, if a developer desires to customize the parts equivalent to callback_options in bolt-js/bolt-python in the OAuth flow, the developer has to implement the whole OAuthV2SuccessHandler with mostly the same code with DefaultOAuthV2SuccessHandler.

app.oauthCallback(new OAuthV2SuccessHandler() {
  @Override
  public Response handle(OAuthCallbackRequest request, Response response, OAuthV2AccessResponse apiResponse) {
    // Implement your own logic here
    return null;
  }
});

Since v1.14, bolt-java provides App#oauthPersistenceCallback and App#oauthPersistenceErrorCallback methods to accept more granular callbacks. These callbacks can be used for customizing the way your app behaves right after saving (or failing to save) issued tokens and their metadata in your database.

var oauthApp = new App(config);

// To customize the behavior after the installation persistence:
// The default behavior is to display the default completion web page
// or to redirect the installer to the pre-given completion URL.
oauthApp.oauthPersistenceCallback(arguments -> {
  var response = arguments.getResponse();
  response.setStatusCode(200);
  response.setContentType("text/plain; charset=utf-8");
  response.setBody("OK!");
});

// To customize the behavior when the installation persistence fails:
// The default behavior is to display the default error web page
// or to redirect the installer to the pre-given failure URL.
oauthApp.oauthPersistenceErrorCallback(arguments -> {
  var response = arguments.getResponse();
  response.setStatusCode(500);
  response.setContentType("text/plain; charset=utf-8");
  response.setBody("Something wrong! (" + arguments.getError().getMessage() + ")");
});

apps.put("/slack/oauth/", oauthApp.asOAuthApp(true));
var server = new SlackAppServer(apps);
server.start();

Apart from the two we added in this version, the following callbacks have been also available for customizing some parts of your app's OAuth flow:

// in the case where the "error" parameter is passed from the Slack OAuth flow
oauthApp.oauthCallbackError((request, response) -> {
  response.setStatusCode(401);
  response.setContentType("text/plain; charset=utf-8");
  response.setBody("Something wrong! (" + request.getPayload().getError() + ")");
  return response;
});

// in the case where the "state" parameter is invalid
oauthApp.oauthCallbackStateError((request, response) -> {
  response.setStatusCode(401);
  response.setContentType("text/plain; charset=utf-8");
  response.setBody("Something wrong! (state is invalid)");
  return response;
});

// in the case where an error code is returned from the oauth.v2.access API
oauthApp.oauthCallbackAccessError((OAuthV2AccessErrorHandler) (request, response, apiResponse) -> {
  response.setStatusCode(401);
  response.setContentType("text/plain; charset=utf-8");
  response.setBody("Something wrong! (" + apiResponse.getError() + ")");
  return response;
});

With that, bolt-java's OAuth flow module now provides even greater flexibility for developers. If you still see missing pieces in the module, please let us know in the GitHub issue tracker 🙇

Slack guest configuration in SCIM APIs

The SCIM API client now supports "urn:scim:schemas:extension:slack:guest:1.0" schema. In your Java code, you can attach the Slack guest specific attributes in a simple way:

var newGuestUser = new User();
newGuestUser.setName(new User.Name());
newGuestUser.getName().setGivenName("Kazuhiro");
newGuestUser.getName().setFamilyName("Sera");
newGuestUser.setUserName("seratch");
var email = new User.Email();
email.setValue("[email protected]");
newGuestUser.setEmails(Arrays.asList(email));

// ISO 8601 date time string
var df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
var expiration = df.format(Date.from(ZonedDateTime.now().plusDays(14).toInstant()));
var slackGuest = User.SlackGuest.builder().type(User.SlackGuest.Types.MULTI).expiration(expiration).build();
newGuestUser.setSlackGuest(slackGuest);

var response = slack.scim(orgAdminToken).createUser(req -> req.user(newGuestUser));

To learn more about the schema itself, please refer to the SCIM API document: https://api.slack.com/scim#post-multi-channel-guest

Changes

  • [bolt] #875 #883 Add callback_options equivalent to Bolt for Java - Thanks @seratch
  • [slack-api-client] #886 #862 Add "urn:scim:schemas:extension:slack:guest:1.0" schema support in the SCIM API client - Thanks @seratch
  • [slack-api-client] #887 #888 auth.revoke API call with a "Sign in with Slack" causes an "invalid_auth" error - Thanks @erathorus @seratch
  • [slack-api-client] #882 Add admin.users.session.resetBulk API support - Thanks @seratch
  • [docs] #881 Document fix: Code snippet error in the OAuth document section - Thanks @jaebradley