<reponame>MeekoI/ais-sdk
import urllib.request
import urllib.parse
import json
import ais_sdk.ais as ais
import ais_sdk.utils as utils

def get_token(username, password, domain):
    region_name = utils.get_region()

    auth_data = {
        "auth": {
            "identity": {

                "password": {
                    "user": {
                        "name": username,
                        "password": password,
                        "domain": {
                            "name": domain
                        }
                    }
                },
                "methods": [
                    "password"
                ]
            },
            "scope": {
                "project": {
                    "name": region_name
                }
            }
        }
    }

    _headers = {
        'Content-Type': 'application/json'
    }
    _url = 'https://' + ais.AisEndpoint.IAM_ENPOINT + ais.TokenURI.AIS_TOKEN

    data = json.dumps(auth_data).encode('utf8')
    req = urllib.request.Request(_url, data, _headers)
    r = urllib.request.urlopen(req)
    X_TOKEN = r.headers['X-Subject-Token']
    return X_TOKEN

import urllib.request
import urllib.parse
import json
import ais_sdk.ais as ais
import ais_sdk.utils as utils

def get_token(username, password, domain):
    region_name = utils.get_region()

    auth_data = {
        "auth": {
            "identity": {

                "password": {
                    "user": {
                        "name": username,
                        "password": password,
                        "domain": {
                            "name": domain
                        }
                    }
                },
                "methods": [
                    "password"
                ]
            },
            "scope": {
                "project": {
                    "name": region_name
                }
            }
        }
    }

    _headers = {
        'Content-Type': 'application/json'
    }
    _url = 'https://' + ais.AisEndpoint.IAM_ENPOINT + ais.TokenURI.AIS_TOKEN

    data = json.dumps(auth_data).encode('utf8')
    req = urllib.request.Request(_url, data, _headers)
    r = urllib.request.urlopen(req)
    X_TOKEN = r.headers['X-Subject-Token']
    return X_TOKEN