ServiceNow との統合中に OAuth リフレッシュトークンを使用すると、Ansible Automation Platform で 401 Unauthorized エラーが発生するのはなぜですか?
Environment
- Ansible Automation Platform
- Service Now
Issue
- Refresh_token OAuth 認証情報を使用して、Ansible Automation Platform を ServiceNow に接続しようとすると、401 Unauthorized エラーがスローされます。
Resolution
-
servicenow.itsmバージョン 1.4.0 以降に追加された機能には、now.pyインベントリープラグインの refresh_token として grant_type が含まれます。 -
この KCS の作成時点では、
servicenow.itsmバージョン 2.0.0 がリリースされています。grant_typeパラメーターは、コレクションフォルダーのnow.pyファイル内で確認できます。grant_type: description: - Grant type used for OAuth authentication. - If not set, the value of the C(SN_GRANT_TYPE) environment variable will be used. choices: [ 'password', 'refresh_token' ] default: password env: - name: SN_GRANT_TYPE type: str version_added: 1.4.0 -
アップグレードが不可能な場合は、以下のように各行を手動で更新すると、itsm コレクションバージョン 1.3 以下の更新トークンでインベントリーが正しく動作するようになります。
File location: ./servicenow/itsm/plugins/inventory/now.py def _get_instance_from_env(self): return dict( host=os.getenv("SN_HOST"), username=os.getenv("SN_USERNAME"), password=os.getenv("SN_PASSWORD"), client_id=os.getenv("SN_CLIENT_ID"), client_secret=os.getenv("SN_SECRET_ID"), refresh_token=os.getenv("SN_REFRESH_TOKEN"), grant_type=os.getenv("SN_GRANT_TYPE"), timeout=os.getenv("SN_TIMEOUT"), )
Root Cause
- servicenow.itsm バージョン 1.3.x には、now.py インベントリープラグインの refresh_token として grant_type が含まれていません。
Diagnostic Steps
-
次のコマンドを使用して、インストールされているコレクションが refresh_token として grant_type をサポートしているか確認します。
# grep -i refresh_token ./collections/ansible_collections/servicenow/itsm/plugins/inventory/now.py` choices: [ 'password', 'refresh_token' ] refresh_token: - If not set, the value of the C(SN_REFRESH_TOKEN) environment - Required when I(grant_type=refresh_token). - name: SN_REFRESH_TOKEN refresh_token=os.getenv("SN_REFRESH_TOKEN"),
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments