Skip to content

Commit 383dd5f

Browse files
WilliamBergaminClaude
andauthored
feat: add AuthProviderBlock layout block support (#1659)
* feat: add AuthProviderBlock layout block support Models the auth_provider block from Standardized App Auth, which parses to UnknownBlock today. Adds the Blocks.authProvider() helper, the Gson factory case, and the Kotlin DSL builder. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * docs: align AuthProviderBlock javadoc with the block kit reference Takes field descriptions and limits from the auth provider block reference and phrases them like the other block models: the limit on its own "Maximum length for ..." line, with no "Required" markers. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> * docs: add missing AuthProviderBlock length limits and simplify isConnected Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> --------- Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent 61c038e commit 383dd5f

9 files changed

Lines changed: 425 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.slack.api.model.kotlin_extension.block
2+
3+
import com.slack.api.model.block.AuthProviderBlock
4+
import com.slack.api.model.block.LayoutBlock
5+
import com.slack.api.model.block.composition.PlainTextObject
6+
import com.slack.api.model.block.element.OverflowMenuElement
7+
import com.slack.api.model.kotlin_extension.block.container.MultiLayoutBlockContainer
8+
import com.slack.api.model.kotlin_extension.block.element.OverflowMenuElementBuilder
9+
10+
@BlockLayoutBuilder
11+
class AuthProviderBlockBuilder : Builder<AuthProviderBlock> {
12+
private var blockId: String? = null
13+
private var value: String? = null
14+
private var name: PlainTextObject? = null
15+
private var isConnected: Boolean? = null
16+
private var description: PlainTextObject? = null
17+
private var iconUrl: String? = null
18+
private var authUrl: String? = null
19+
private var disconnectUrl: String? = null
20+
private var connectedIdentity: PlainTextObject? = null
21+
private var connectedContext: PlainTextObject? = null
22+
private var accessory: OverflowMenuElement? = null
23+
private var fallback: List<LayoutBlock>? = null
24+
25+
fun blockId(id: String) {
26+
blockId = id
27+
}
28+
29+
fun value(value: String) {
30+
this.value = value
31+
}
32+
33+
fun name(text: String, emoji: Boolean? = null) {
34+
name = PlainTextObject(text, emoji)
35+
}
36+
37+
fun name(textObject: PlainTextObject) {
38+
name = textObject
39+
}
40+
41+
fun isConnected(connected: Boolean) {
42+
isConnected = connected
43+
}
44+
45+
fun description(text: String, emoji: Boolean? = null) {
46+
description = PlainTextObject(text, emoji)
47+
}
48+
49+
fun description(textObject: PlainTextObject) {
50+
description = textObject
51+
}
52+
53+
fun iconUrl(url: String) {
54+
iconUrl = url
55+
}
56+
57+
fun authUrl(url: String) {
58+
authUrl = url
59+
}
60+
61+
fun disconnectUrl(url: String) {
62+
disconnectUrl = url
63+
}
64+
65+
fun connectedIdentity(text: String, emoji: Boolean? = null) {
66+
connectedIdentity = PlainTextObject(text, emoji)
67+
}
68+
69+
fun connectedIdentity(textObject: PlainTextObject) {
70+
connectedIdentity = textObject
71+
}
72+
73+
fun connectedContext(text: String, emoji: Boolean? = null) {
74+
connectedContext = PlainTextObject(text, emoji)
75+
}
76+
77+
fun connectedContext(textObject: PlainTextObject) {
78+
connectedContext = textObject
79+
}
80+
81+
fun accessory(builder: OverflowMenuElementBuilder.() -> Unit) {
82+
accessory = OverflowMenuElementBuilder().apply(builder).build()
83+
}
84+
85+
fun fallback(builder: MultiLayoutBlockContainer.() -> Unit) {
86+
fallback = MultiLayoutBlockContainer().apply(builder).underlying
87+
}
88+
89+
override fun build(): AuthProviderBlock {
90+
return AuthProviderBlock.builder()
91+
.blockId(blockId)
92+
.value(value)
93+
.name(name)
94+
.isConnected(isConnected)
95+
.description(description)
96+
.iconUrl(iconUrl)
97+
.authUrl(authUrl)
98+
.disconnectUrl(disconnectUrl)
99+
.connectedIdentity(connectedIdentity)
100+
.connectedContext(connectedContext)
101+
.accessory(accessory)
102+
.fallback(fallback)
103+
.build()
104+
}
105+
}

‎slack-api-model-kotlin-extension/src/main/kotlin/com/slack/api/model/kotlin_extension/block/container/MultiLayoutBlockContainer.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class MultiLayoutBlockContainer : LayoutBlockDsl {
3232
underlying += ContainerBlockBuilder().apply(builder).build()
3333
}
3434

35+
override fun authProvider(builder: AuthProviderBlockBuilder.() -> Unit) {
36+
underlying += AuthProviderBlockBuilder().apply(builder).build()
37+
}
38+
3539
override fun context(builder: ContextBlockBuilder.() -> Unit) {
3640
underlying += ContextBlockBuilder().apply(builder).build()
3741
}

‎slack-api-model-kotlin-extension/src/main/kotlin/com/slack/api/model/kotlin_extension/block/dsl/LayoutBlockDsl.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ interface LayoutBlockDsl {
4343
*/
4444
fun container(builder: ContainerBlockBuilder.() -> Unit)
4545

46+
/**
47+
* Displays authentication provider information, including its icon, name, and connection state.
48+
*
49+
* @see <a href="https://docs.slack.dev/reference/block-kit/blocks/auth-provider-block">Auth provider documentation</a>
50+
*/
51+
fun authProvider(builder: AuthProviderBlockBuilder.() -> Unit)
52+
4653
/**
4754
* Displays message context, which can include both images and text.
4855
*
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package test_locally.block
2+
3+
import com.slack.api.model.block.AuthProviderBlock
4+
import com.slack.api.model.block.Blocks.authProvider
5+
import com.slack.api.model.block.Blocks.section
6+
import com.slack.api.model.block.composition.BlockCompositions.markdownText
7+
import com.slack.api.model.block.composition.BlockCompositions.option
8+
import com.slack.api.model.block.composition.BlockCompositions.plainText
9+
import com.slack.api.model.block.element.BlockElements.overflowMenu
10+
import com.slack.api.model.kotlin_extension.block.withBlocks
11+
import org.junit.Test
12+
import kotlin.test.assertEquals
13+
14+
class AuthProviderBlockTest {
15+
16+
@Test
17+
fun constructDisconnectedAuthProvider() {
18+
val expected = authProvider { it
19+
.value("acme")
20+
.name(plainText("Acme"))
21+
.isConnected(false)
22+
.authUrl("https://acme.example.com/oauth")
23+
}
24+
25+
val actual = withBlocks {
26+
authProvider {
27+
value("acme")
28+
name("Acme")
29+
isConnected(false)
30+
authUrl("https://acme.example.com/oauth")
31+
}
32+
}
33+
34+
assertEquals(listOf(expected), actual)
35+
}
36+
37+
@Test
38+
fun constructConnectedAuthProviderWithAllFields() {
39+
val expected = authProvider { it
40+
.blockId("auth1")
41+
.value("acme")
42+
.name(plainText("Acme", true))
43+
.isConnected(true)
44+
.description(plainText("Search Acme docs"))
45+
.iconUrl("https://acme.example.com/icon.png")
46+
.authUrl("https://acme.example.com/oauth")
47+
.disconnectUrl("https://acme.example.com/disconnect")
48+
.connectedIdentity(plainText("jane@acme.example.com"))
49+
.connectedContext(plainText("Acme Corp"))
50+
.accessory(overflowMenu { menu -> menu
51+
.actionId("acme_menu")
52+
.options(listOf(
53+
option(plainText("Switch accounts"), "switch"),
54+
option(plainText("Disconnect"), "disconnect")
55+
))
56+
})
57+
.fallback(listOf(section { s -> s.text(markdownText("Connected to Acme")) }))
58+
}
59+
60+
val actual = withBlocks {
61+
authProvider {
62+
blockId("auth1")
63+
value("acme")
64+
name("Acme", emoji = true)
65+
isConnected(true)
66+
description("Search Acme docs")
67+
iconUrl("https://acme.example.com/icon.png")
68+
authUrl("https://acme.example.com/oauth")
69+
disconnectUrl("https://acme.example.com/disconnect")
70+
connectedIdentity("jane@acme.example.com")
71+
connectedContext("Acme Corp")
72+
accessory {
73+
actionId("acme_menu")
74+
options {
75+
option {
76+
plainText("Switch accounts")
77+
value("switch")
78+
}
79+
option {
80+
plainText("Disconnect")
81+
value("disconnect")
82+
}
83+
}
84+
}
85+
fallback {
86+
section {
87+
markdownText("Connected to Acme")
88+
}
89+
}
90+
}
91+
}
92+
93+
assertEquals(listOf(expected), actual)
94+
}
95+
96+
@Test
97+
fun constructAuthProviderWithTextObjects() {
98+
val name = plainText("Acme", true)
99+
val identity = plainText("jane@acme.example.com")
100+
101+
val actual = withBlocks {
102+
authProvider {
103+
value("acme")
104+
name(name)
105+
isConnected(true)
106+
connectedIdentity(identity)
107+
}
108+
}
109+
110+
val block = actual[0] as AuthProviderBlock
111+
assertEquals(name, block.name)
112+
assertEquals(identity, block.connectedIdentity)
113+
}
114+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.slack.api.model.block;
2+
3+
import com.slack.api.model.block.composition.PlainTextObject;
4+
import com.slack.api.model.block.element.OverflowMenuElement;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.util.List;
11+
12+
/**
13+
* Displays authentication provider information, including its icon, name, and connection state.
14+
*
15+
* https://docs.slack.dev/reference/block-kit/blocks/auth-provider-block
16+
*/
17+
@Data
18+
@Builder
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
public class AuthProviderBlock implements LayoutBlock {
22+
public static final String TYPE = "auth_provider";
23+
private final String type = TYPE;
24+
25+
/**
26+
* Unique identifier for this provider within the app. Included in interaction payloads and used to derive
27+
* the connect button's {@code action_id} ({@code auth_provider_connect_<value>}).
28+
* Maximum length for this field is 150 characters.
29+
*/
30+
private String value;
31+
32+
/**
33+
* Human-readable name of the provider.
34+
* Maximum length for the text in this field is 75 characters.
35+
*/
36+
private PlainTextObject name;
37+
38+
/**
39+
* Whether this provider is currently connected. Slack records this state for the user.
40+
*/
41+
private Boolean isConnected;
42+
43+
/**
44+
* Brief description of what this connection enables.
45+
* Maximum length for the text in this field is 150 characters.
46+
*/
47+
private PlainTextObject description;
48+
49+
/**
50+
* URL for the provider icon image. Must be https. Falls back to the app's avatar when absent.
51+
* Maximum length for this field is 3000 characters.
52+
*/
53+
private String iconUrl;
54+
55+
/**
56+
* OAuth redirect URL opened when the user clicks Connect. Must be https, on a host listed in the
57+
* app manifest's {@code features.user_connections.auth_hosts}.
58+
* Maximum length for this field is 3000 characters.
59+
*/
60+
private String authUrl;
61+
62+
/**
63+
* URL opened when the user clicks Disconnect. Must be https, on a host listed in the
64+
* app manifest's {@code features.user_connections.auth_hosts}.
65+
* Maximum length for this field is 3000 characters.
66+
*/
67+
private String disconnectUrl;
68+
69+
/**
70+
* Display name of the connected account, shown when {@code is_connected} is true.
71+
* Maximum length for the text in this field is 75 characters.
72+
*/
73+
private PlainTextObject connectedIdentity;
74+
75+
/**
76+
* Additional context about the connection (e.g., org or workspace name).
77+
* Maximum length for the text in this field is 75 characters.
78+
*/
79+
private PlainTextObject connectedContext;
80+
81+
/**
82+
* Overflow menu shown when connected (e.g., Disconnect, Re-authenticate).
83+
*/
84+
private OverflowMenuElement accessory;
85+
86+
/**
87+
* Stable blocks rendered by clients that don't recognize {@code auth_provider}, spliced into the parent
88+
* blocks array.
89+
*/
90+
private List<LayoutBlock> fallback;
91+
92+
private String blockId;
93+
}

‎slack-api-model/src/main/java/com/slack/api/model/block/Blocks.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public static AlertBlock alert(ModelConfigurator<AlertBlock.AlertBlockBuilder> c
135135
return configurator.configure(AlertBlock.builder()).build();
136136
}
137137

138+
// AuthProviderBlock
139+
140+
public static AuthProviderBlock authProvider(ModelConfigurator<AuthProviderBlock.AuthProviderBlockBuilder> configurator) {
141+
return configurator.configure(AuthProviderBlock.builder()).build();
142+
}
143+
138144
// CardBlock
139145

140146
public static CardBlock card(ModelConfigurator<CardBlock.CardBlockBuilder> configurator) {

‎slack-api-model/src/main/java/com/slack/api/util/json/GsonLayoutBlockFactory.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ private Class<? extends LayoutBlock> getLayoutClassInstance(String typeName) {
3737
return ActionsBlock.class;
3838
case AlertBlock.TYPE:
3939
return AlertBlock.class;
40+
case AuthProviderBlock.TYPE:
41+
return AuthProviderBlock.class;
4042
case CallBlock.TYPE:
4143
return CallBlock.class;
4244
case CardBlock.TYPE:

0 commit comments

Comments
 (0)