Connect-Dify
Warning
This help was primarily created by a generative AI. It may contain partially inaccurate expressions.
SYNOPSIS
Authenticate with Dify using password, email-based login, or pre-obtained access token, enabling operations with other PSDify cmdlets.
SYNTAX
Connect-Dify [[-Server] <String>] [[-AuthMethod] <String>] [[-Email] <String>] [[-Token] <String>]
[[-Code] <String>] [[-Password] <SecureString>] [-AccessToken <SecureString>] [-CSRFToken <SecureString>]
[-Force] [<CommonParameters>]
DESCRIPTION
The Connect-Dify cmdlet allows you to authenticate with a Dify server using various methods such as password-based login, email-based code authentication, or access token authentication. After successful authentication, some variables required for subsequent operations are set.
NOTE: This help was primarily created by a generative AI. It may contain partially inaccurate expressions.
EXAMPLES
Example 1
Email authentication, mainly for the Dify Cloud Edition. Enter the code manually which will be sent to your email address after execution.
SSO-authenticated accounts can also log in via email authentication using the associated email address.
You can use following environment variables to simplify cmdlet arguments: $env:PSDIFY_URL = "https://cloud.dify.ai", $env:PSDIFY_AUTH_METHOD = "Code", $env:PSDIFY_EMAIL = "dify@example.com".
Example 2
Password authentication, mainly for the Dify Community Edition. Enter the password manually after execution.
If using a self-signed certificate for HTTPS in the Community Edition, disable certificate verification by Set-PSDifyConfiguration -IgnoreSSLVerification $true or set $env:PSDIFY_DISABLE_SSL_VERIFICATION = "true" before invoking Connect-Dify.
You can use following environment variables to simplify cmdlet arguments: $env:PSDIFY_URL = "https://dify.example.com", $env:PSDIFY_AUTH_METHOD = "Password", $env:PSDIFY_EMAIL = "dify@example.com", $env:PSDIFY_PASSWORD = "AwesomeDify123!".
Example 3
$DifyPassword = ConvertTo-SecureString -String "AwesomeDify123!" -AsPlainText -Force
Connect-Dify -Server "https://dify.example.com" -Email "dify@example.com" -Password $DifyPassword
Password authentication with predefined password.
Example 4
$AccessToken = ConvertTo-SecureString -String "eyJhbGci..." -AsPlainText -Force
$CSRFToken = ConvertTo-SecureString -String "eyJhbGci..." -AsPlainText -Force
Connect-Dify -Server "https://dify.example.com" -AuthMethod "AccessToken" -AccessToken $AccessToken -CSRFToken $CSRFToken
Access token authentication using a pre-obtained access token and CSRF token. This method is available for Dify 1.9.2 or later, and is useful when you already have valid tokens (e.g., extracted from a browser session) and want to avoid re-authentication.
This method is particularly useful in environments where password-based authentication is not available, such as:
- Dify Enterprise Edition with SSO (Single Sign-On) enabled, where direct password login is not supported.
- Dify Cloud Edition, where only email-based code authentication is available interactively.
In these cases, you can obtain the access_token and csrf_token from your browser's cookies after logging in manually, and pass them to this cmdlet.
You can use following environment variables to simplify cmdlet arguments: $env:PSDIFY_URL = "https://dify.example.com", $env:PSDIFY_AUTH_METHOD = "AccessToken", $env:PSDIFY_ACCESS_TOKEN = "eyJhbGci...", $env:PSDIFY_CSRF_TOKEN = "eyJhbGci...".
The companion Chrome/Edge extension "PSDify Helper" can extract these tokens from your browser session and copy the complete login command to your clipboard with a single right-click - no developer tools needed. For details, refer to the "Browser Extension" page in the PSDify documentation.
PARAMETERS
-AccessToken
Specifies the access token for access token authentication. This parameter accepts a secure string.
This also can be set using the environment variable $env:PSDIFY_ACCESS_TOKEN. If both are provided, the argument takes priority.
Type: SecureString
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AuthMethod
Specifies the authentication method to use. Valid values are:
Password: Authenticate using an email and password.Code: Authenticate using an email and a code sent via email.AccessToken: Authenticate using a pre-obtained access token and CSRF token. Requires Dify 1.9.2 or later.
This also can be set using the environment variable $env:PSDIFY_AUTH_METHOD. If both are provided, the argument takes priority. The default value is Password.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Code
Specifies the one-time code sent to the email address for email-based code authentication.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-CSRFToken
Specifies the CSRF token for access token authentication. This parameter accepts a secure string.
This also can be set using the environment variable $env:PSDIFY_CSRF_TOKEN. If both are provided, the argument takes priority.
Type: SecureString
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies the email address to use for authentication. This is required for both password-based and email-based code authentication methods.
This also can be set using the environment variable $env:PSDIFY_EMAIL. If both are provided, the argument takes priority.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Force
Forces re-authentication even if valid tokens are already set in the environment variables.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Password
Specifies the password to use for password-based authentication. This parameter accepts a secure string.
This also can be set using the environment variable $env:PSDIFY_PASSWORD. If both are provided, the argument takes priority.
Type: SecureString
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Server
Specifies the server URL to connect to. If not specified, the default value is https://cloud.dify.ai.
This also can be set using the environment variable $env:PSDIFY_URL. If both are provided, the argument takes priority.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Token
Specifies the validation token to use for code-based authentication.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
None
OUTPUTS
System.Object
NOTES
After a successful authentication, the following variables, along with others, are set:
$script:PSDIFY_CONSOLE_AUTH$env:PSDIFY_URL$env:PSDIFY_VERSION
If these variables are already set and valid, re-authentication is not performed unless the -Force parameter is specified.