-
Notifications
You must be signed in to change notification settings - Fork 444
Personal Access Token Authentication #465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shinchris
merged 7 commits into
tableau:development
from
fpagliar:users/fpagliaricci/personal-access-tokens-auth
Jul 26, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3180cd7
Adding model for PersonalAccessToken authentication information
fpagliar 5203610
Making the signin request accept generic credentials
fpagliar 0e24bb0
Adding login sample
fpagliar 9b64846
adding sign in tests for tokens
fpagliar 887417b
Fixing lint issues
fpagliar e906c4c
moving auth credentials to a property
fpagliar 784d35f
Making PAT use a specific sign in method, to avoid misuing the featur…
fpagliar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,52 @@ | ||
#### | ||
# This script demonstrates how to log in to Tableau Server Client. | ||
# | ||
# To run the script, you must have installed Python 2.7.9 or later. | ||
#### | ||
|
||
import argparse | ||
import getpass | ||
import logging | ||
|
||
import tableauserverclient as TSC | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Logs in to the server.') | ||
|
||
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', | ||
help='desired logging level (set to error by default)') | ||
|
||
parser.add_argument('--server', '-s', required=True, help='server address') | ||
|
||
group = parser.add_mutually_exclusive_group(required=True) | ||
group.add_argument('--username', '-u', help='username to sign into the server') | ||
group.add_argument('--token-name', '-n', help='name of the personal access token used to sign into the server') | ||
|
||
args = parser.parse_args() | ||
|
||
# Set logging level based on user input, or error by default. | ||
logging_level = getattr(logging, args.logging_level.upper()) | ||
logging.basicConfig(level=logging_level) | ||
|
||
# Make sure we use an updated version of the rest apis. | ||
server = TSC.Server(args.server, use_server_version=True) | ||
|
||
if args.username: | ||
# Trying to authenticate using username and password. | ||
password = getpass.getpass("Password: ") | ||
tableau_auth = TSC.TableauAuth(args.username, password) | ||
with server.auth.sign_in(tableau_auth): | ||
print('Logged in successfully') | ||
|
||
else: | ||
# Trying to authenticate using personal access tokens. | ||
personal_access_token = getpass.getpass("Personal Access Token: ") | ||
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=args.token_name, | ||
personal_access_token=personal_access_token) | ||
with server.auth.sign_in_with_personal_access_token(tableau_auth): | ||
print('Logged in successfully') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
class PersonalAccessTokenAuth(object): | ||
def __init__(self, token_name, personal_access_token, site_id=''): | ||
self.token_name = token_name | ||
self.personal_access_token = personal_access_token | ||
self.site_id = site_id | ||
# Personal Access Tokens doesn't support impersonation. | ||
self.user_id_to_impersonate = None | ||
|
||
@property | ||
def credentials(self): | ||
return {'clientId': self.token_name, 'personalAccessToken': self.personal_access_token} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.