-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DOCSP-43473: oidc * vale * fix * wip * log error * dedent * emphasis * fix * MD tech review 1 (cherry picked from commit 8a67edf)
- Loading branch information
Showing
9 changed files
with
430 additions
and
4 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
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,5 @@ | ||
.. note:: | ||
|
||
If your ``AuthMechanismProperties`` struct field values | ||
include a comma, you must create a ``Credential`` instance | ||
to set your authentication options. |
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,28 @@ | ||
package main | ||
|
||
import ( | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func main() { | ||
// start-azure-imds-client | ||
uri := "mongodb://<hostname>:<port>" | ||
props := map[string]string{ | ||
"ENVIRONMENT": "azure", | ||
"TOKEN_RESOURCE": "<audience>", | ||
} | ||
opts := options.Client().ApplyURI(uri) | ||
opts.SetAuth( | ||
options.Credential{ | ||
Username: "<Azure client ID or application ID>", | ||
AuthMechanism: "MONGODB-OIDC", | ||
AuthMechanismProperties: props, | ||
}, | ||
) | ||
client, err := mongo.Connect(opts) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// end-azure-imds-client | ||
} |
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func main() { | ||
// start-custom-callback | ||
eksCallback := func(_ context.Context, | ||
_ *options.OIDCArgs) (*options.OIDCCredential, error) { | ||
accessToken, err := os.ReadFile( | ||
os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &options.OIDCCredential{ | ||
AccessToken: string(accessToken), | ||
}, nil | ||
} | ||
// end-custom-callback | ||
|
||
// start-credential-callback | ||
uri := "mongodb://<hostname>:<port>" | ||
opts := options.Client().ApplyURI(uri) | ||
opts.SetAuth( | ||
options.Credential{ | ||
AuthMechanism: "MONGODB-OIDC", | ||
OIDCMachineCallback: eksCallback, | ||
}, | ||
) | ||
client, err := mongo.Connect(opts) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// end-credential-callback | ||
} |
Oops, something went wrong.