我试图authorisation.py
在包api中的蓝图内访问访问应用程序配置.我正在初始化__init__.py
其中使用的蓝图authorisation.py
.
__init__.py
from flask import Blueprint
api_blueprint = Blueprint("xxx.api", __name__, None)
from api import authorisation
Run Code Online (Sandbox Code Playgroud)
authorisation.py
from flask import request, jsonify, current_app
from ..oauth_adapter import OauthAdapter
from api import api_blueprint as api
client_id = current_app.config.get('CLIENT_ID')
client_secret = current_app.config.get('CLIENT_SECRET')
scope = current_app.config.get('SCOPE')
callback = current_app.config.get('CALLBACK')
auth = OauthAdapter(client_id, client_secret, scope, callback)
@api.route('/authorisation_url')
def authorisation_url():
url = auth.get_authorisation_url()
return str(url)
Run Code Online (Sandbox Code Playgroud)
我得到RuntimeError:在应用程序上下文之外工作
我明白为什么会这样,但是访问这些配置设置的正确方法是什么?
----更新----暂时,我已经这样做了.
@api.route('/authorisation_url')
def authorisation_url():
client_id, client_secret, scope, callback = config_helper.get_config()
auth = OauthAdapter(client_id, client_secret, …
Run Code Online (Sandbox Code Playgroud) 有人使用Flask-Security
扩展进行身份验证吗?如何使注册视图起作用?
http://packages.python.org/Flask-Security/customizing.html
我指的是上面的链接.
@app.route('/register', methods=['GET'])
def register():
return render_template('security/register_user.html')
Run Code Online (Sandbox Code Playgroud)
我不想扩展默认类,我只想在我的站点布局中包装默认注册视图,所以我这样做了.
{% extends "layout.html" %}
{% block title %}upload{% endblock %}
{% block body %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% include "security/_messages.html" %}
<h1>Register</h1>
<form action="{{ url_for_security('register') }}" method="POST" name="register_user_form">
{{ register_user_form.hidden_tag() }}
{{ render_field_with_errors(register_user_form.email) }}
{{ render_field_with_errors(register_user_form.password) }}
{% if register_user_form.password_confirm %}
{{ render_field_with_errors(register_user_form.password_confirm) }}
{% endif %}
{{ render_field(register_user_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误?
werkzeug.routing.BuildError
BuildError: ('security.register', {}, None)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JWT实现spring AuthorizationServer.我能够生成JWT令牌并登录,直到我将BCrypt添加到混音中.现在,当我尝试登录时,我从API获得"Bad credentials".
OAuth2Configuration.java
@Configuration
@EnableAuthorizationServer
public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {
private DataSource dataSource;
private AuthenticationManager authenticationManager;
private BCryptPasswordEncoder passwordEncoder;
public OAuth2Configuration(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
this.dataSource = new Jdbc3PoolingDataSource();
this.passwordEncoder = new BCryptPasswordEncoder();
}
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.passwordEncoder(passwordEncoder);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("api-client")
.secret("verysecretivesecret")
.scopes("READ", "WRITE", "DELETE")
.authorizedGrantTypes("implicit", "refresh_tokens", "password", "authorization_code");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authorizationCodeServices(authorizationCodeServices())
.tokenStore(tokenStore())
.tokenEnhancer(jwtTokenEnhancer())
.authenticationManager(authenticationManager);
}
@Bean …
Run Code Online (Sandbox Code Playgroud) java spring spring-security spring-security-oauth2 spring-cloud
我正在尝试使用TweetSharp获取最近的200条推文,但由于某种原因它返回12.
var service = new TwitterService(
_consumerKey,
_consumerSecret,
tokenClaim,
tokenSecret
);
IAsyncResult result = service.BeginListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200}
IEnumerable<TwitterStatus> tweets = service.EndListTweetsOnUserTimeline(result);
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样?谢谢
更新
以下如何从TweetSharp的ListTweetOnHomeTimeline()方法获取最多800条推文?
IAsyncResult result =
_twitterService.BeginListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200 });
IEnumerable<TwitterStatus> tweets = _twitterService.EndListTweetsOnUserTimeline(result).ToArray();
var tweet2 = _twitterService.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200, MaxId = tweets.Last().Id });
return tweet2;
Run Code Online (Sandbox Code Playgroud)
tweet2是空的.
我有以下的Nest查询来删除所有匹配的文档,非常直接,但我收到了400个错误的请求.
var client = new ElasticClient();
var request = new DeleteByQueryRequest<Type>("my-index")
{
Query = new QueryContainer(
new TermQuery
{
Field = "versionId",
Value = "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
}
)
};
var response = client.DeleteByQuery(request);
Assert.IsTrue(response.IsValid);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
---------------更新---------------
请求机构
{"query":{"term":{"versionId":{"value":"ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"}}}}
Run Code Online (Sandbox Code Playgroud)
响应机构
{"took":0,"timed_out":false,"_indices":{"_all":{"found":0,"deleted":0,"missing":0,"failed":0}},"failures":[]}
Run Code Online (Sandbox Code Playgroud)
在Sense插件中查询:
GET /my-index/type/_search
{
"query": {
"match": {
"versionId": "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
}
}
}
Run Code Online (Sandbox Code Playgroud)
查询响应:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 116,
"max_score": 2.1220484,
"hits": []
...
}}
Run Code Online (Sandbox Code Playgroud)
--------------- NEST QUERY …
我正在尝试使用 IIS 7.5 设置反向代理。我想要一个与特定 URL 模式匹配的传入请求由 Tomcat 提供服务。我已经使用这里的教程来配置它。
我的设置如下:
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url=".*/(Locations|FacetedSearch|LocationPage)/.*" />
<action type="Rewrite" url="http://search.xxx.com/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" replace="true" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://search.xxx.com/(.*)" />
<action type="Rewrite" value="http{R:1}://dev.xxx.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<tracing>
Run Code Online (Sandbox Code Playgroud)
HTTP 错误 500.52 - URL 重写模块错误。当 HTTP 响应的内容被编码(“deflate”)时,不能应用出站重写规则。
我在系统中有两种类型的用户,我想在注册时分配适当的组。参考如何在使用 django-allauth 时自定义用户配置文件,我想我可以覆盖注册表单并执行以下操作:
class CustomSignupForm(forms.Form):
login_widget = forms.TextInput(attrs={'type': 'email',
'placeholder': _('email'),
'autofocus': 'autofocus',
'class': 'form-control'
})
email = forms.EmailField(label='Email', widget=login_widget)
password = PasswordField(label='Password', widget=forms.PasswordInput(attrs={'class': 'form-control'}))
password2 = PasswordField(label='Re-type Password', widget=forms.PasswordInput(attrs={'class': 'form-control'}))
def save(self, request, user):
role = request.GET.get('type')
print(role)
group = role or "group1"
g = Group.objects.get(name=group)
user.groups.add(g)
user.save()
Run Code Online (Sandbox Code Playgroud)
但我不断收到以下错误:
save() missing 1 required positional argument: 'user'
Run Code Online (Sandbox Code Playgroud)
此外,我已将 allauth 配置为使用电子邮件登录。
谢谢你的帮助。
我需要创建一份调查表.不同类型的用户将在调查中回答不同的问题集.
models.py
from django.contrib.auth.models import Group, User
from django.db import models
ANSWER_CHOICES = (
('0', 'No'),
('1', 'Yes')
)
class Survey(models.Model):
name = models.CharField(max_length=100)
group = models.ForeignKey(Group)
def __str__(self):
return self.name
class Feature(models.Model):
name = models.CharField(max_length=150)
survey = models.ForeignKey(Survey)
def __str__(self):
return self.name
class Rating(models.Model):
rating = models.IntegerField(choices=ANSWER_CHOICES)
feature = models.ForeignKey(Feature)
rating_for = models.ForeignKey(User, related_name='rated_user')
rating_by = models.ForeignKey(User, related_name='rated_by')
def __str__(self):
return str.format("%s - %s", self.feature, self.rating)
Run Code Online (Sandbox Code Playgroud)
每个问题(特征)的答案(评级)是单选按钮的是或否.用户提交表单后,会将答案保存在评级表中.
django实现这个目标的方法是什么?
谢谢
forms.py
from django import forms
from django.forms import modelformset_factory, TextInput …
Run Code Online (Sandbox Code Playgroud) 我正在使用 webflux 和 keycloak 构建 OIDC 客户端。我的 spring 应用程序无法启动,因为它找不到下面的 bean:
Consider defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' in your configuration.
Run Code Online (Sandbox Code Playgroud)
接着...
构建.gradle
dependencies {
compile "org.springframework.boot:spring-boot-starter-webflux:2.0.3.RELEASE"
compile "org.springframework.security:spring-security-oauth2-client"
compile "org.springframework.security:spring-security-oauth2-jose"
compile "org.springframework.boot:spring-boot-devtools"
compile group: 'org.keycloak', name: 'keycloak-services', version: '4.0.0.Final'
compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '4.0.0.Final'
compile "org.projectlombok:lombok"
compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '4.0.0.Beta4'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
spring:
security:
oauth2:
client:
registration:
google:
client-id: your-app-client-id
client-secret: your-app-client-secret
facebook:
client-id: your-app-client-id
client-secret: your-app-client-secret
keycloak:
provider: keycloak
client-id: auth-api
client-secret: 727bea9d-6e01-433a-960b-83ac5d939adf …
Run Code Online (Sandbox Code Playgroud) 我有一个这样的模型
class Job(models.Model):
description = models.CharField(max_length=255)
user = models.ForeignKey(User)
date = models.DateField()
slot = models.CharField(max_length=10, choices=SLOT_CHOICES)
location = models.ForeignKey(Location)
objects = JobManager()
searches = geomodels.GeoManager()
class Meta:
verbose_name_plural = "Job"
unique_together = ('date', 'slot', 'user')
def __str__(self):
return "{0}-{1}".format(self.user.first_name, self.date)
class Applied(models.Model):
user = models.ForeignKey(User)
job = models.ForeignKey(Job, null=True, blank=True)
action_taken = models.BooleanField(default=False)
is_declined = models.BooleanField(default=False)
class Meta:
verbose_name_plural = "Job Applications"
unique_together = ('user', 'job', )
Run Code Online (Sandbox Code Playgroud)
我想搜索日期范围之间的所有作业,并显示用户是否可以申请,已经申请或已被拒绝.应用程序信息在应用模型中.
jobs = Job.searches.filter(**kwargs)\
.filter(date__range=(date_from, date_to),
visibility=VisibilityStatus.PUBLIC,
status=JobStatus.AVAILABLE)\
.prefetch_related('applied_set')\
.select_related('user__surgeryprofile__location')\
.order_by('date')
Run Code Online (Sandbox Code Playgroud)
但我不能让它工作,它没有在数据库中的应用表上进行左连接.任何建议如何让它工作.
谢谢
django ×3
c# ×2
django-1.7 ×2
flask ×2
java ×2
.net ×1
django-forms ×1
iis-7 ×1
keycloak ×1
nest ×1
python ×1
spring ×1
spring-boot ×1
spring-cloud ×1
tweetsharp ×1
twitter ×1