Skip to content

Commit 4754db4

Browse files
nelsonmaiaramya18101duedares-rvj
authored
Feature/session transfer (#1180)
* adding support for Native to Web SSO - Session Transfer * adding support for Native to Web SSO - Session Transfer * Refactor managing apps session transfer * Add integration test and handle nil check * updated go.mod * minor fix --------- Co-authored-by: ramya18101 <[email protected]> Co-authored-by: Rajat Bajaj <[email protected]> Co-authored-by: Rajat Bajaj <[email protected]>
1 parent 56ac07d commit 4754db4

14 files changed

+379
-1
lines changed

docs/auth0_apps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The term application or app in Auth0 does not imply any particular implementatio
1313
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
1414
- [auth0 apps list](auth0_apps_list.md) - List your applications
1515
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
16+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
1617
- [auth0 apps show](auth0_apps_show.md) - Show an application
1718
- [auth0 apps update](auth0_apps_update.md) - Update an application
1819
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ auth0 apps create [flags]
7070
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
7171
- [auth0 apps list](auth0_apps_list.md) - List your applications
7272
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
73+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
7374
- [auth0 apps show](auth0_apps_show.md) - Show an application
7475
- [auth0 apps update](auth0_apps_update.md) - Update an application
7576
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_delete.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ auth0 apps delete [flags]
5151
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
5252
- [auth0 apps list](auth0_apps_list.md) - List your applications
5353
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
54+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
5455
- [auth0 apps show](auth0_apps_show.md) - Show an application
5556
- [auth0 apps update](auth0_apps_update.md) - Update an application
5657
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ auth0 apps list [flags]
5050
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
5151
- [auth0 apps list](auth0_apps_list.md) - List your applications
5252
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
53+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
5354
- [auth0 apps show](auth0_apps_show.md) - Show an application
5455
- [auth0 apps update](auth0_apps_update.md) - Update an application
5556
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_open.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ auth0 apps open [flags]
3838
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
3939
- [auth0 apps list](auth0_apps_list.md) - List your applications
4040
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
41+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
4142
- [auth0 apps show](auth0_apps_show.md) - Show an application
4243
- [auth0 apps update](auth0_apps_update.md) - Update an application
4344
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_session-transfer.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: default
3+
has_toc: false
4+
has_children: true
5+
---
6+
# auth0 apps session-transfer
7+
8+
9+
10+
## Commands
11+
12+
- [auth0 apps session-transfer show](auth0_apps_session-transfer_show.md) - Show session transfer settings for an app
13+
- [auth0 apps session-transfer update](auth0_apps_session-transfer_update.md) - Update session transfer settings for an app
14+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
layout: default
3+
parent: auth0 apps session-transfer
4+
has_toc: false
5+
---
6+
# auth0 apps session-transfer show
7+
8+
9+
10+
## Usage
11+
```
12+
auth0 apps session-transfer show [flags]
13+
```
14+
15+
## Examples
16+
17+
```
18+
auth0 apps session-transfer show
19+
auth0 apps session-transfer show <app-id>
20+
auth0 apps session-transfer show <app-id> --json
21+
```
22+
23+
24+
## Flags
25+
26+
```
27+
--json Output in json format.
28+
```
29+
30+
31+
## Inherited Flags
32+
33+
```
34+
--debug Enable debug mode.
35+
--no-color Disable colors.
36+
--no-input Disable interactivity.
37+
--tenant string Specific tenant to use.
38+
```
39+
40+
41+
## Related Commands
42+
43+
- [auth0 apps session-transfer show](auth0_apps_session-transfer_show.md) - Show session transfer settings for an app
44+
- [auth0 apps session-transfer update](auth0_apps_session-transfer_update.md) - Update session transfer settings for an app
45+
46+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
layout: default
3+
parent: auth0 apps session-transfer
4+
has_toc: false
5+
---
6+
# auth0 apps session-transfer update
7+
8+
9+
10+
## Usage
11+
```
12+
auth0 apps session-transfer update [flags]
13+
```
14+
15+
## Examples
16+
17+
```
18+
auth0 apps session-transfer update
19+
auth0 apps session-transfer update <app-id>
20+
auth0 apps session-transfer update <app-id> --can-create-token --json
21+
auth0 apps session-transfer update <app-id> --can-create-token=true --allowed-auth-methods=cookie,query --enforce-device-binding=ip
22+
```
23+
24+
25+
## Flags
26+
27+
```
28+
-m, --allowed-auth-methods strings Comma-separated list of authentication methods (e.g., cookie, query).
29+
-t, --can-create-token Allow creation of session transfer tokens.
30+
-e, --enforce-device-binding string Device binding enforcement: 'none', 'ip', or 'asn'.
31+
--json Output in json format.
32+
```
33+
34+
35+
## Inherited Flags
36+
37+
```
38+
--debug Enable debug mode.
39+
--no-color Disable colors.
40+
--no-input Disable interactivity.
41+
--tenant string Specific tenant to use.
42+
```
43+
44+
45+
## Related Commands
46+
47+
- [auth0 apps session-transfer show](auth0_apps_session-transfer_show.md) - Show session transfer settings for an app
48+
- [auth0 apps session-transfer update](auth0_apps_session-transfer_update.md) - Update session transfer settings for an app
49+
50+

docs/auth0_apps_show.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ auth0 apps show [flags]
4646
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
4747
- [auth0 apps list](auth0_apps_list.md) - List your applications
4848
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
49+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
4950
- [auth0 apps show](auth0_apps_show.md) - Show an application
5051
- [auth0 apps update](auth0_apps_update.md) - Update an application
5152
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_update.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ auth0 apps update [flags]
7070
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
7171
- [auth0 apps list](auth0_apps_list.md) - List your applications
7272
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
73+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
7374
- [auth0 apps show](auth0_apps_show.md) - Show an application
7475
- [auth0 apps update](auth0_apps_update.md) - Update an application
7576
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

docs/auth0_apps_use.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ auth0 apps use [flags]
4444
- [auth0 apps delete](auth0_apps_delete.md) - Delete an application
4545
- [auth0 apps list](auth0_apps_list.md) - List your applications
4646
- [auth0 apps open](auth0_apps_open.md) - Open the settings page of an application
47+
- [auth0 apps session-transfer](auth0_apps_session-transfer.md) - Manage session transfer settings for an application
4748
- [auth0 apps show](auth0_apps_show.md) - Show an application
4849
- [auth0 apps update](auth0_apps_update.md) - Update an application
4950
- [auth0 apps use](auth0_apps_use.md) - Choose a default application for the Auth0 CLI

internal/cli/apps.go

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ var (
135135
ShortForm: "n",
136136
Help: "Number of apps to retrieve. Minimum 1, maximum 1000.",
137137
}
138+
appSTCanCreateToken = Flag{
139+
Name: "Can Create Token",
140+
LongForm: "can-create-token",
141+
ShortForm: "t",
142+
Help: "Allow creation of session transfer tokens.",
143+
AlwaysPrompt: true,
144+
}
145+
appSTAllowedAuthMethods = Flag{
146+
Name: "Allowed Auth Methods",
147+
LongForm: "allowed-auth-methods",
148+
ShortForm: "m",
149+
Help: "Comma-separated list of authentication methods (e.g., cookie, query).",
150+
AlwaysPrompt: true,
151+
}
152+
appSTEnforceDeviceBinding = Flag{
153+
Name: "Enforce Device Binding",
154+
LongForm: "enforce-device-binding",
155+
ShortForm: "e",
156+
Help: "Device binding enforcement: 'none', 'ip', or 'asn'.",
157+
AlwaysPrompt: true,
158+
}
138159
refreshToken = Flag{
139160
Name: "Refresh Token",
140161
LongForm: "refresh-token",
@@ -161,6 +182,7 @@ func appsCmd(cli *cli) *cobra.Command {
161182
cmd.AddCommand(updateAppCmd(cli))
162183
cmd.AddCommand(deleteAppCmd(cli))
163184
cmd.AddCommand(openAppCmd(cli))
185+
cmd.AddCommand(appsSessionTransferCmd(cli))
164186

165187
return cmd
166188
}
@@ -969,3 +991,159 @@ func (c *cli) appPickerOptions(requestOpts ...management.RequestOption) pickerOp
969991
return append(priorityOpts, opts...), nil
970992
}
971993
}
994+
995+
// Session Transfer.
996+
func appsSessionTransferCmd(cli *cli) *cobra.Command {
997+
cmd := &cobra.Command{
998+
Use: "session-transfer",
999+
Short: "Manage session transfer settings for an application",
1000+
}
1001+
1002+
cmd.SetUsageTemplate(resourceUsageTemplate())
1003+
cmd.AddCommand(appsSessionTransferShowCmd(cli))
1004+
cmd.AddCommand(appsSessionTransferUpdateCmd(cli))
1005+
1006+
return cmd
1007+
}
1008+
1009+
func appsSessionTransferShowCmd(cli *cli) *cobra.Command {
1010+
var inputs struct {
1011+
ID string
1012+
}
1013+
1014+
cmd := &cobra.Command{
1015+
Use: "show",
1016+
Args: cobra.MaximumNArgs(1),
1017+
Short: "Show session transfer settings for an app",
1018+
Example: `auth0 apps session-transfer show
1019+
auth0 apps session-transfer show <app-id>
1020+
auth0 apps session-transfer show <app-id> --json`,
1021+
RunE: func(cmd *cobra.Command, args []string) error {
1022+
if len(args) == 0 {
1023+
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
1024+
if err != nil {
1025+
return err
1026+
}
1027+
} else {
1028+
inputs.ID = args[0]
1029+
}
1030+
1031+
var client *management.Client
1032+
if err := ansi.Waiting(func() error {
1033+
var err error
1034+
client, err = cli.api.Client.Read(cmd.Context(), inputs.ID)
1035+
return err
1036+
}); err != nil {
1037+
return fmt.Errorf("failed to read application: %w", err)
1038+
}
1039+
1040+
if client.SessionTransfer == nil {
1041+
cli.renderer.Infof("No session transfer settings configured for app %s", ansi.Faint(inputs.ID))
1042+
return nil
1043+
}
1044+
1045+
cli.renderer.SessionTransferShow(client)
1046+
1047+
return nil
1048+
},
1049+
}
1050+
1051+
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
1052+
return cmd
1053+
}
1054+
1055+
func appsSessionTransferUpdateCmd(cli *cli) *cobra.Command {
1056+
var inputs struct {
1057+
ID string
1058+
CanCreateToken bool
1059+
AllowedAuthMethods []string
1060+
EnforceDeviceBinding string
1061+
}
1062+
1063+
cmd := &cobra.Command{
1064+
Use: "update",
1065+
Args: cobra.MaximumNArgs(1),
1066+
Short: "Update session transfer settings for an app",
1067+
Example: ` auth0 apps session-transfer update
1068+
auth0 apps session-transfer update <app-id>
1069+
auth0 apps session-transfer update <app-id> --can-create-token --json
1070+
auth0 apps session-transfer update <app-id> --can-create-token=true --allowed-auth-methods=cookie,query --enforce-device-binding=ip`,
1071+
RunE: func(cmd *cobra.Command, args []string) error {
1072+
if len(args) == 0 {
1073+
err := appID.Pick(cmd, &inputs.ID, cli.appPickerOptions())
1074+
if err != nil {
1075+
return err
1076+
}
1077+
} else {
1078+
inputs.ID = args[0]
1079+
}
1080+
1081+
var (
1082+
current *management.Client
1083+
st management.SessionTransfer
1084+
)
1085+
1086+
if err := ansi.Waiting(func() (err error) {
1087+
current, err = cli.api.Client.Read(cmd.Context(), inputs.ID)
1088+
return err
1089+
}); err != nil {
1090+
return fmt.Errorf("failed to find application with ID %q: %w", inputs.ID, err)
1091+
}
1092+
1093+
if current.SessionTransfer == nil {
1094+
current.SessionTransfer = &management.SessionTransfer{
1095+
CanCreateSessionTransferToken: auth0.Bool(false),
1096+
AllowedAuthenticationMethods: &[]string{},
1097+
EnforceDeviceBinding: auth0.String("ip"),
1098+
}
1099+
}
1100+
1101+
if err := appSTCanCreateToken.AskBoolU(cmd, &inputs.CanCreateToken, current.SessionTransfer.CanCreateSessionTransferToken); err != nil {
1102+
return err
1103+
}
1104+
1105+
defaultVal := stringSliceToCommaSeparatedString(current.SessionTransfer.GetAllowedAuthenticationMethods())
1106+
if err := appSTAllowedAuthMethods.AskManyU(cmd, &inputs.AllowedAuthMethods, &defaultVal); err != nil {
1107+
return err
1108+
}
1109+
1110+
if err := appSTEnforceDeviceBinding.SelectU(cmd, &inputs.EnforceDeviceBinding, []string{"none", "ip", "asn"}, current.SessionTransfer.EnforceDeviceBinding); err != nil {
1111+
return err
1112+
}
1113+
1114+
// Set the flag if it was supplied or entered by the prompt.
1115+
if appSTCanCreateToken.IsSet(cmd) || shouldPromptWhenNoLocalFlagsSet(cmd) {
1116+
st.CanCreateSessionTransferToken = &inputs.CanCreateToken
1117+
}
1118+
1119+
if len(inputs.AllowedAuthMethods) > 0 {
1120+
st.AllowedAuthenticationMethods = &inputs.AllowedAuthMethods
1121+
}
1122+
1123+
if inputs.EnforceDeviceBinding != "" {
1124+
st.EnforceDeviceBinding = &inputs.EnforceDeviceBinding
1125+
} else {
1126+
st.EnforceDeviceBinding = current.SessionTransfer.EnforceDeviceBinding
1127+
}
1128+
1129+
// Send update request.
1130+
clientST := &management.Client{SessionTransfer: &st}
1131+
if err := ansi.Waiting(func() error {
1132+
return cli.api.Client.Update(cmd.Context(), inputs.ID, clientST)
1133+
}); err != nil {
1134+
return fmt.Errorf("failed to update session transfer: %w", err)
1135+
}
1136+
1137+
cli.renderer.SessionTransferUpdate(clientST, inputs.ID)
1138+
return nil
1139+
},
1140+
}
1141+
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
1142+
1143+
// Register CLI flags.
1144+
appSTCanCreateToken.RegisterBoolU(cmd, &inputs.CanCreateToken, false)
1145+
appSTAllowedAuthMethods.RegisterStringSliceU(cmd, &inputs.AllowedAuthMethods, nil)
1146+
appSTEnforceDeviceBinding.RegisterStringU(cmd, &inputs.EnforceDeviceBinding, "")
1147+
1148+
return cmd
1149+
}

0 commit comments

Comments
 (0)