我已经使用 spring boot 和 Google 成功完成了 OAuth2 登录,但我想将登录限制在特定域(我们使用的是 Google Apps for Work)。
我认为我应该通过扩展类 OAuth2ClientAuthenticationProcessingFilter (如本线程中所指定)来处理,但我不确定如何做到这一点。
基本上,我想使用 Google OAuth 2.0 作为身份提供者,但必须只接受公司用户 (@company.com)。
我使用的Django与Tastypie库和Django的OAuth的工具包,以及用于Django的OAuth的工具包Tastypie认证.
免责声明:我有可能完全错误.如果是这样,请纠正我,引导我走向不那么无知的人.
主要问题:如何安全地创建用户?
我的理解:
get或者post,客户端需要一个令牌.我正在努力解决这个问题.当客户端尝试创建不需要OAuth2的帐户时,我会创建吗?或者有没有办法在没有登录的情况下使用OAuth2,只允许客户创建帐户?
任何帮助深表感谢!
我有这个问题,当我尝试使用XHR通过Facebook登录我的网站上的用户时,我的请求被阻止了,但是,如果我复制XHR请求的URL并将其粘贴到浏览器中,就可以登录。
因此,这是一个简单的示意图:
为什么XHR被阻止在浏览器可以访问的相同URL上?
完整的错误是这样的:
events.js:160
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND https://api.instagram.com https://api.instagram.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
Run Code Online (Sandbox Code Playgroud)
我得到错误的代码是这样的:
var express = require('express');
var app = express();
var https = require('https');
app.get('/oauth/ig', function (req, res) {
var options = {
hostname: 'https://api.instagram.com',
path: '/oauth/access_token?client_secret=myClientSecret&grant_type=authorization_code&redirect_uri=http://localhost:1992/oauth/ig&code='+req.query.code,
method: 'POST',
};
var igRequest = https.request(options, (response) => {
res.send("response");
});
})
Run Code Online (Sandbox Code Playgroud)
我正在使用 nodejs 并且正在尝试进行 Instagram OAUTH。
您好,我尝试使用 YouTube 数据 API 从 YouTube 视频下载字幕。我自定义了YouTube 生成的示例代码。
#!/usr/bin/python
# Usage example:
# python captions.py --videoid='<video_id>' --name='<name>' --file='<file>' --language='<language>' --action='action'
import httplib2
import os
import sys
from apiclient.discovery import build_from_document
from apiclient.errors import HttpError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
# The CLIENT_SECRETS_FILE variable specifies the name of a file that contains
# the OAuth 2.0 information for this application, including its client_id and
# client_secret. You can acquire …Run Code Online (Sandbox Code Playgroud) 我在Laravel 5中设置了Passport,并在用户使用此注册时创建了令牌。
$user->createToken('My Token')->accessToken;
Run Code Online (Sandbox Code Playgroud)
当我创建一个新用户时,我可以在oauth_access_tokens表中看到一个看起来像这样的条目,我缩短了显示的ID ...
id | user_id | client_id | name | scopes | revoked
-----------------------------------------------------------
765765 | 193 | 1 | My Token | [] | 0
Run Code Online (Sandbox Code Playgroud)
我想允许访问的API路由受到保护,现在我试图通过在邮递员中传递以下标头来允许访问...
Authorization | Bearer 765765
Accept | application/json
Run Code Online (Sandbox Code Playgroud)
但这返回未经身份验证的响应,我在哪里出错?
我的项目正在运行Laravel 5.4,我通常使用passportapi通过api进行身份验证bearer token。一切正常,但是当未经授权的用户尝试访问需要身份验证的资源时,该用户会收到错误消息405 method not allowed

但我希望得到回应401 unauthorized。如何更改此设置,仅发送带有消息的响应,而不发送异常?我做了调查,但没有发现任何东西。我使用标准laravel中间件授权auth:api。我的路线归入中间件
Route::group(['middleware' => 'auth:api'], function () {
// these routes should return 401 if user not authenticated
}
Run Code Online (Sandbox Code Playgroud) 上下文
我正在使用Angular,Express和PassportJS 构建无状态应用程序,并希望使用他们的Google帐户对用户进行身份验证.在对用户进行身份验证后,我的目标是使用JWT令牌来拥有无状态应用程序.
角2侧
点击Google登录按钮后,我的服务中会执行以下代码:
login() {
return this.http.get('http://localhost:3000/api/auth/google');
}
Run Code Online (Sandbox Code Playgroud)
表达方面
在Express上,执行以下操作:
// This gets executed first after clicking the sign in using Google button.
router.get('/api/auth/google', passport.authenticate('google', {
session: false,
scope: ['profile', 'email']
}));
// Google sends me back here (callback).
passport.use(new GoogleStrategy({
clientID: 'omitted',
clientSecret: 'omitted',
callbackURL: '/api/auth/google/callback'
}, function (accessToken, refreshToken, profile, cb) {
// Here, I obtain the profile and create a JWT token which I send back to the user.
let jwtToken = generateToken(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用symfony 4.2安装HWI oauth捆绑软件,但是它不起作用。我按照描述的步骤进行操作:https : //github.com/hwi/HWIOAuthBundle/blob/master/Resources/doc/1-setting_up_the_bundle.md但它不起作用。
在作曲家的输出下面:
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Using version ^0.6.3 for hwi/oauth-bundle
Using version ^2.0 for php-http/guzzle6-adapter
Using version ^1.14 for php-http/httplug-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install hwi/oauth-bundle 0.6.3
- php-http/client-common v1.6.0 requires symfony/options-resolver ^2.6 || ^3.0 -> no matching …Run Code Online (Sandbox Code Playgroud) Auth()->check()不断返回假。该api仅具有api中间件,我希望访客和登录用户都可以使用它。
我尝试从请求标头中获取授权令牌,但是我不知道有什么方法可以检查哪个用户拥有此令牌。
if(Auth()->check()){
//return extra data
} else {
//return something else
}
Run Code Online (Sandbox Code Playgroud)
Auth()->check()即使标头中包含Ive承载令牌,为什么总是返回false?如果标头具有令牌,则应返回true