Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Add authentication via API token #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bvoilar
Copy link

@bvoilar bvoilar commented Nov 1, 2023

Description

Add support for authentication using API Access Tokens. The authentication follows RFC6749 (OAuth 2.0). This is useful if an external identity provider is configured for authentication with vCloud Director.

If user is set to "API_TOKEN" the password is interpreted as token and instead of setting the login credentials of the pyvcloud client, the client's rehydrate_from_token function is called with the token and the optional argument is_jwt_token=True.

Implements: #223

Usage

  1. Generate an API Access Token
  2. Run an ad-hoc command and test the authentication via API Access Token, e.g.:
    ansible localhost \
         -m vcd_vapp \
         -a "api_version=34.0
             host=<VCD_HOST>
             operation=list_vms
             org=<VCD_ORG>
             password=<GENERATED_TOKEN>
             user=API_TOKEN
             vapp_name=<VCD_VAPP>
             vdc=<VCD_DATACENTER>"
    

Add support for authentication with API tokens as described in [Generate
an API Access Token][1]. The authentication follows RFC6749 (OAuth 2.0).
If the user is set to 'API_TOKEN' the password is interpreted as token
string and instead of setting the login credentials of the pyvcloud
client, the client's rehydrate_from_token function is called with the
optional argument is_jwt_token=True.

[1]: https://docs.vmware.com/en/VMware-Cloud-Director/10.3/VMware-Cloud-Director-Tenant-Portal-Guide/GUID-A1B3B2FA-7B2C-4EE1-9D1B-188BE703EEDE.html

Signed-off-by: Martin Fleischer <[email protected]>
@bvoilar bvoilar force-pushed the Add-api-token-authentication branch from 3f4fa8a to 9ce8de8 Compare November 1, 2023 12:30
@@ -43,7 +44,15 @@ def login(self):
api_version=api_version,
verify_ssl_certs=verify_ssl_certs)

self.client.set_credentials(BasicLoginCredentials(user, org, password))
if user == 'API_TOKEN':
oAuthResponse = post(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to pass verify=verify_ssl_certs as option to post() so that in case someone says verify_ssl_certs: False in their tasks it would do as it is supposed to

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants