问题标签 [django-oauth]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2770 浏览

python - 具有自定义用户模型的 django-oauth2-provider?

我现在真的被困在我的项目中。我正在尝试为我的应用程序实现 Oauth2。我发现了很多关于 django-oauth2-provider 并尝试了它。唯一的问题是,它使用了 django.contrib.auth 中的 User 模型。我们站点的主要用户保存在一个名为 User 的自定义模型中,该模型不继承或扩展 django.contrib.auth 中的模型。

有什么方法可以使用我的自定义用户模型来创建客户端和令牌?

如果 django-oauth2-provider 不能用于此目的,任何人都可以向我推荐一些 oauth2 库,可以选择用我自己的模型实现 oauth2。

真挚地,

苏珊特·卡尔基

0 投票
1 回答
125 浏览

oauth-2.0 - 如何使用 OAuth2.0 授权访问受保护的 Django 提供的 HTML 页面

有没有办法使用django-oauth-toolkit提供的 OAuth access_token 授予用户访问受保护的 Django-serve HTML 页面的权限?

我正在为第 3 方应用程序开发一个插件,用户通过弹出窗口启动 OAuth 流程,以接收插件调用我们的 REST API 所需的 access_token。用户稍后必须访问我们应用程序中受保护的 HTML 页面,但 OAuth 无法访问此页面,因为它需要django-allauth设置的身份验证。这会导致用户登录两次,这不是令人愉快的用户体验。

在使用 GET 访问此 HTML 页面时,我尝试设置授权标头,但这似乎不适用于 HTTP。也许我需要创建一个自定义中间件来处理这个问题,但我不确定。想知道有没有其他人遇到过这种情况。

0 投票
4 回答
7419 浏览

python - 使用 Django OAuth2 Toolkit 生成单一访问令牌

我正在使用最新的Django OAuth2 Toolkit (0.10.0)和 Python 2.7、Django 1.8 和 Django REST framework 3.3

在使用 时grant_type=password,我注意到任何时候用户要求新的访问令牌时都会出现一些奇怪的行为:

创建一个的访问令牌和刷新令牌。在令牌超时之前,的访问和刷新令牌仍然可用!

我的问题:

  • 我需要的是,每次用户请求新的访问令牌时,旧的访问令牌都会变得无效、无法使用并被删除。
  • 此外,有没有办法让密码咕噜声类型不会创建刷新令牌。我在我的应用程序中没有任何用处。

我发现的一种解决方案是REST Framework OAuth一次提供一个访问令牌的配置。我不急于使用该提供商,但我可能别无选择。

0 投票
0 回答
123 浏览

django - Django OAuth 注册并在同一视图中获取令牌

我正在尝试创建一个注册视图,该视图既可以根据 POST 数据注册用户模型,也可以在响应中包括:

  1. 创建的用户数据(即{'username': 'foo.bar', 'email': 'test@test.io'}
  2. 令牌数据(即{'expires_in': 36000, 'access_token': 'foo', 'scope': 'read write', 'token_type': 'Bearer', 'refresh_token': 'bar'}

因此,他们不必在注册后登录。我正在尝试使用这个views.py:

但是我不知道我应该如何获得我的提供者client_idclient_secret(我创建了我的 oauth2_provider 应用程序)。

我应该把它当作 inmy_app = oauth2_provider.models.Application.objects.all()[0]然后把它们当作my_app.client_idandmy_app.client_secret吗?有更好的方法吗?

另外,这有任何安全漏洞吗?

谢谢!

0 投票
1 回答
418 浏览

python - Extra protection layer for Django Rest Framework and OAuth2 Toolkit

This is a follow up question for this.

I'm using the latest Django OAuth2 Toolkit (0.10.0) with Python 2.7, Django 1.8 and Django REST framework 3.3

Some background:
When authenticating, the client receive a new AccessToken that he uses every time a makes a new request to the server. This AccessToken is owned by the client and being transferred using Authorization header upon request.

A simple test that I made was grabbing this access token from an authenticated client and send it in the Authorization header using a simple HTTP request from a different machine.
The result was that this new "client" is now authenticated just like the original client, and he can make requests as he pleased.

So the issue is:
The access token is not bind to any form of client validation (Like session id or client IP address). Any one that can get/find/steal/lookup the client's AccessToken, can be fake requests on behalf of this client.

I researched this issue allot but I couldn't find any one who addressed this matter. Maybe i'm doing something wrong in the from of authenticating the client? I would love some insights. Maybe its a simple configuration, out-of-the-box solution that I missed.

Thanks!

0 投票
1 回答
2092 浏览

python - 如何使用 Django Oauth Toolkit 通过移动/otp 登录

我们将 Django OAuth Toolkit 与 DRF(Django Rest Framework)一起使用。现在,我们要提供手机号码登录。为了进行身份验证,我们将使用 OTP(一次性密码)。如何做到这一点?

  • 一种解决方案是直接创建 auth-token,这看起来并不明智。
0 投票
0 回答
157 浏览

ruby-on-rails - 如何让 Rails 使用基于 django-oauth-toolkit 的 OAuth2 提供程序

我正在尝试让 Rails 应用程序使用我使用 django-oauth-toolkit 设置的外部 OAuth2 提供程序。我使用 omniauth-oauth2 策略作为基础,并为身份验证和令牌 URL 设置我自己的本地 URL。https://github.com/intridea/omniauth-oauth2

在身份验证阶段发送的 redirect_uri 与为获取令牌而发送的略有不同。它有额外的参数:状态和代码。由于额外的参数,django-oauth-toolkit 将此 URL 视为与原始 URL 不同。想知道这是否是 rails 方面的问题,django 方面的问题,或者与我设置它的方式有关。

0 投票
1 回答
374 浏览

django - 在返回登录 OAuth2 中包含参数

我正在使用第三方库通过使用python-social-auth-oauthdjango-toolkit的社交网络检索令牌。

除了常规参数之外,我还想添加检查用户的组列表。

当前回报:

{"scope":"write read groups","token_type":"Bearer","expires_in":36000,"refresh_token":"xxx","access_token":"xxx"}

0 投票
1 回答
335 浏览

django - Django oauth2 工具包:即使在 1 年后也不必登录?

我正在使用 Ionic2 为前端开发移动应用程序,django rest 框架用于后端,django oauth2 工具包用于身份验证。移动应用用户提交邮箱和密码的同时,服务器返回client_id、access_token和refresh_token并保存在手机本地存储中。每当移动应用程序用户打开应用程序时,它都会请求访问令牌和客户端 ID,以便他们可以自动登录用户。如果此过程失败,它会再次请求刷新令牌以获取新的访问令牌。

我的问题是,我的做法是否适合移动用户在第一次之后不再需要登录?甚至移动应用程序用户在很长一段时间后打开应用程序,例如 1 年,移动应用程序用户是否仍有可能在不重新登录的情况下登录?

我只是想确定刷新令牌是否有任何限制时间或某些可能性..提前谢谢大家!

0 投票
1 回答
4162 浏览

django - 如何从 django-oauth-toolkit 令牌获取当前登录用户?

我正在使用 Django 和 django-oauth-toolkit 为 Auth0 构建通用OAuth2 授权服务器。我计划使用 Django 服务器对用户进行多种不同服务的身份验证,使用 Auth0 作为中介。

我有一个在应用程序通过身份验证后调用的视图,我需要该视图来返回当前登录用户的详细信息。

网址.py:

意见/current_user.py:

request.user正在返回 AnonymousUser,而不是令牌所属的用户。

如何访问与 django-oauth-toolkit 颁发的令牌关联的 Django 用户?