-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for AD federated authentication login sequence
- Loading branch information
1 parent
095ece7
commit ab16ce1
Showing
13 changed files
with
1,083 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
/.idea | ||
/.connstr | ||
.vscode | ||
.terraform | ||
*.tfstate* | ||
*.log | ||
*.swp | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package mssql | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// Federated authentication library affects the login data structure and message sequence. | ||
const ( | ||
// FedAuthLibraryLiveIDCompactToken specifies the Microsoft Live ID Compact Token authentication scheme | ||
FedAuthLibraryLiveIDCompactToken = 0x00 | ||
|
||
// FedAuthLibrarySecurityToken specifies a token-based authentication where the token is available | ||
// without additional information provided during the login sequence. | ||
FedAuthLibrarySecurityToken = 0x01 | ||
|
||
// FedAuthLibraryADAL specifies a token-based authentication where a token is obtained during the | ||
// login sequence using the server SPN and STS URL provided by the server during login. | ||
FedAuthLibraryADAL = 0x02 | ||
|
||
// FedAuthLibraryReserved is used to indicate that no federated authentication scheme applies. | ||
FedAuthLibraryReserved = 0x7F | ||
) | ||
|
||
// Federated authentication ADAL workflow affects the mechanism used to authenticate. | ||
const ( | ||
// FedAuthADALWorkflowPassword uses a username/password to obtain a token from Active Directory | ||
FedAuthADALWorkflowPassword = 0x01 | ||
|
||
// FedAuthADALWorkflowPassword uses the Windows identity to obtain a token from Active Directory | ||
FedAuthADALWorkflowIntegrated = 0x02 | ||
|
||
// FedAuthADALWorkflowMSI uses the managed identity service to obtain a token | ||
FedAuthADALWorkflowMSI = 0x03 | ||
) | ||
|
||
type FederatedAuthenticationState struct { | ||
// FedAuthWorkflow captures the "fedauth" connection parameter | ||
FedAuthWorkflow string | ||
|
||
// UserName is initially set to the user id connection parameter. | ||
// The federated authentication configurer can modify this value to | ||
// change what is sent in the login packet. | ||
UserName string | ||
|
||
// Password is initially set to the user id connection parameter. | ||
// The federated authentication configurer can modify this value to | ||
// change what is sent in the login packet. | ||
Password string | ||
|
||
// Password is initially set to the client cert path connection parameter. | ||
ClientCertPath string | ||
|
||
// FedAuthLibrary is populated by the federated authentication provider. | ||
FedAuthLibrary int | ||
|
||
// ADALWorkflow is populated by the federated authentication provider. | ||
ADALWorkflow byte | ||
|
||
// FedAuthEcho is populated from the prelogin response | ||
FedAuthEcho bool | ||
|
||
// FedAuthToken is populated during login with the value from the provider. | ||
FedAuthToken string | ||
|
||
// Nonce is populated during login with the value from the provider. | ||
Nonce []byte | ||
|
||
// Signature is populated during login with the value from the server. | ||
Signature []byte | ||
} | ||
|
||
// FederatedAuthenticationProvider implementations use the connection string | ||
// parameters to determine the library and workflow, if any, and obtain tokens | ||
// during the login sequence. | ||
type FederatedAuthenticationProvider interface { | ||
// Configure accepts the incoming connection parameters and determines | ||
// the values for the authentication library and ADAL workflow. | ||
ConfigureProvider(fedAuth *FederatedAuthenticationState) error | ||
|
||
// ProvideActiveDirectoryToken implementations are called during federated | ||
// authentication login sequences where the server provides a service | ||
// principal name and security token service endpoint that should be used | ||
// to obtain the token. Implementations should contact the security token | ||
// service specified and obtain the appropriate token, or return an error | ||
// to indicate why a token is not available. | ||
ProvideActiveDirectoryToken(ctx context.Context, serverSPN, stsURL string) (string, error) | ||
|
||
// ProvideSecurityToken implementations are called during federated | ||
// authentication security token login sequences at the point when the | ||
// security token is required. The string returned should be the access | ||
// token to supply to the server, otherwise an error can be returned to | ||
// indicate why a token is not available. | ||
ProvideSecurityToken(ctx context.Context) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.