From 130ae3f76e2e292dfd40cc15ece4889b0a3eeb88 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sat, 25 Jan 2020 01:21:57 -0500 Subject: [PATCH] Push additional files Update Workflow Update Workflow Update Workflow Update Workflow Update Workflow --- .bumpversion.cfg | 15 ++++++++ .github/workflows/build.yml | 34 +++++++++++++++++++ .github/workflows/version.yml | 40 ++++++++++++++++++++++ cognito_oauthtools/__init__.py | 44 ++++++++++++++++++++++++ requirements.txt | 2 ++ setup.py | 62 ++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+) create mode 100644 .bumpversion.cfg create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/version.yml create mode 100644 cognito_oauthtools/__init__.py create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..db8a8ef --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,15 @@ +[bumpversion] +current_version = 0.0.0 +commit = False +tag = True +tag_name = {new_version} + +[bumpversion:file:cognito_oauthtools/__init__.py] +search = version = "0.0.0" +replace = version = "{new_version}" + +[semver] +main_branches = master +major_branches = +minor_branches = feature +patch_branches = hotfix, bugfix \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2cab88c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build & Publish +on: + release: + types: + - created + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Update Version + run: | + pip install bumpversion + export regex="([0-9]+.[0-9]+.[0-9]+)" + echo ${{ github.ref }} > tag.txt + VERSION=`grep -Po "${regex}" tag.txt` + bumpversion minor --no-tag --new-version ${VERSION} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: build + run: | + python setup.py sdist bdist_wheel + - name: PyPi Publish + uses: pypa/gh-action-pypi-publish@v1.0.0a0 + with: + user: josephbmanley + password: ${{ secrets.PYPI_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..64beabf --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,40 @@ +name: Version & Release + +on: + push: + branches: + - master + +jobs: + CheckVersion: + runs-on: ubuntu-latest + container: + image: rightbrainnetworks/auto-semver + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Run auto-semver + id: semver + run: | + export regex='^\\s*current_version\\s*=\\s*\\K[^\\s]+' + export RETURN_STATUS=`semver -n` + echo "Semver Return Status: ${RETURN_STATUS}" + + export SEMVER_NEW_VERSION=`grep -Po '${regex}' .bumpversion.cfg` + export VERSION=`semver_get_version -d` + + echo ::set-output name=RETURN_STATUS::$RETURN_STATUS + echo ::set-output name=SEMVER_NEW_VERSION::$SEMVER_NEW_VERSION + echo ::set-output name=VERSION::$VERSION + - name: Create Release + id: create_release + uses: actions/create-release@v1 + if: steps['semver']['outputs']['RETURN_STATUS'] == '0' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.semver.outputs.SEMVER_NEW_VERSION }} + release_name: ${{ steps.semver.outputs.SEMVER_NEW_VERSION }} + body: Release Version ${{ steps.semver.outputs.SEMVER_NEW_VERSION }} + draft: false + prerelease: false \ No newline at end of file diff --git a/cognito_oauthtools/__init__.py b/cognito_oauthtools/__init__.py new file mode 100644 index 0000000..191e309 --- /dev/null +++ b/cognito_oauthtools/__init__.py @@ -0,0 +1,44 @@ +import requests + +version = "0.0.0" + +class Client: + def __init__(self, endpoint, client_id, client_secret, host_domain, logout_path="/", redirect_path="/oauth"): + self.endpoint = endpoint + self.client_id = client_id + self.client_secret = client_secret + self.host = host_domain + self.logout_path = logout_path + self.redirect_path = redirect_path + + @property + def loginUrl(self): + return 'https://' + self.endpoint + '/login?client_id=' + self.client_id + "&redirect_uri=https://" + self.host + self.redirect_path + "&response_type=code" + + @property + def registerUrl(self): + return 'https://' + self.endpoint + '/signup?client_id=' + self.client_id + "&redirect_uri=https://" + self.host + self.redirect_path + "&response_type=code" + + @property + def logoutUrl(self): + return 'https://' + self.endpoint + '/logout?client_id=' + self.client_id + "&logout_uri=https://" + self.host + self.logout_path + + def get_token(self, code): + r = requests.post('https://' + self.endpoint + '/oauth2/token', auth=(self.client_id, self.client_secret), + data = {'code':code, 'grant_type':'authorization_code', 'redirect_uri': "https://" + self.host + self.redirect_path }) + return r.json()['access_token'] + +class User: + def __init__(self, client, token = None): + self.data = {} + self.token = token + self.client = client + self.reload() + + def is_logged_in(self): + self.reload() + return 'username' in self.data + + def reload(self): + if self.token: + self.data = requests.post('https://' + self.client.endpoint + '/oauth2/userInfo', headers={'Authorization' :"Bearer " + self.token}).json() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bf62ef9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +wheel +requests \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8c7ebda --- /dev/null +++ b/setup.py @@ -0,0 +1,62 @@ + +import re +from os import path + +from setuptools import setup +from codecs import open + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +def read(*parts): + return open(path.join(here, *parts), 'r').read() + +def find_version(*file_paths): + version_file = read(*file_paths) + version_match = re.search(r"^version = ['\"]([^'\"]*)['\"]", + version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + +setup( + name='cognito-oauthtools', + version=find_version('cognito_oauthtools','__init__.py'), + description='Simple AWS Cognito client to simplify implementation', + long_description=long_description, + long_description_content_type="text/markdown", + + # The project's main homepage. + url='https://github.com/josephbmanley/cognito-oauthtools', + + # Author details + author='Joseph Manley', + author_email='j@cloudsumu.com', + + # Choose your license + license='GPL3.0', + + # See https://pypi.org/classifiers/ + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8' + ], + keywords='AWS,Cognito,OAuth', + packages=["cognito_oauthtools"], + install_requires=['requests'], + package_data={}, + entry_points={} +)