我正在尝试将 Keycloak 实现到我的 Flask Rest 服务,但它总是出现以下错误。
{"error": "invalid_token", "error_description": "需要令牌但无效"}
client_secrets.json
{
"web": {
"issuer": "http://localhost:18080/auth/realms/Dev-Auth",
"auth_uri": "http://localhost:18080/auth/realms/Dev-Auth/protocol/openid-connect/auth",
"client_id": "flask_api",
"client_secret": "0bff8456-9be2-4f82-884e-c7f9bea65bd1",
"redirect_uris": [
"http://localhost:5001/*"
],
"userinfo_uri": "http://localhost:18080/auth/realms/Dev-Auth/protocol/openid-connect/userinfo",
"token_uri": "http://localhost:18080/auth/realms/Dev-Auth/protocol/openid-connect/token",
"token_introspection_uri": "http://localhost:18080/auth/realms/Dev-Auth/protocol/openid-connect/token/introspect",
"bearer_only": "true"
}
}
Run Code Online (Sandbox Code Playgroud)
运行文件
import json
import logging
from flask import Flask, g, jsonify
from flask_oidc import OpenIDConnect
import requests
app = Flask(__name__)
app.config.update({
'SECRET_KEY': 'TESTING-ANURAG',
'TESTING': True,
'DEBUG': True,
'OIDC_CLIENT_SECRETS': 'client_secrets.json',
'OIDC_OPENID_REALM': 'Dev-Auth',
'OIDC_INTROSPECTION_AUTH_METHOD': 'bearer',
'OIDC-SCOPES': ['openid']
})
oidc = OpenIDConnect(app)
@app.route('/api', methods=['GET'])
@oidc.accept_token(require_token=True, scopes_required=['openid'])
def …
Run Code Online (Sandbox Code Playgroud) 我需要以无头模式远程运行我的硒测试用例。
目前,我正在 py.test 命令下运行
py.test --driver remote --host selenium.host --port 4444 --capability browserName firefox --capability platform LINUX
Run Code Online (Sandbox Code Playgroud)
对于无头模式,我需要在conftest.py
文件中处理它
但我需要在命令行中使用该选项,而不是在conftest.py
文件中处理该选项
@pytest.fixture
def chrome_options(chrome_options):
chrome_options.add_argument('--headless')
return chrome_options
@pytest.fixture
def firefox_options(firefox_options):
firefox_options.add_argument('-headless')
return firefox_options
Run Code Online (Sandbox Code Playgroud)