Here a shell-script using python3 and command-line input of needed data:
https://gist.github.com/fleXible/709e4583086b926646cb5304361693b4
#!/usr/bin/env python3
import base64
import hashlib
import http.client
import json
username = input('Username: ')
password = input('Password: ')
client_name = input('Client Name: ')
client_version = input('Client Version: ')
client_id = hashlib.sha512('{} {}'.format(client_name, client_version).encode()).hexdigest()
base64string = base64.b64encode('{}:{}'.format(username, password).encode())
headers = {'Authorization': 'Basic {}'.format(base64string.decode('ascii')),
'X-Plex-Client-Identifier': client_id,
'X-Plex-Product': client_name,
'X-Plex-Version': client_version}
conn = http.client.HTTPSConnection('plex.tv')
conn.request('POST', '/users/sign_in.json', '', headers)
response = conn.getresponse()
print(response.status, response.reason)
data = json.loads(response.read().decode())
print('Auth-Token: {}'.format(data['user']['authentication_token']))
conn.close()