标签: google-authentication

使用 OpenIddict 登录外部提供商获取 Token

我有一个带有 ASP.NET Core 的 API,它将由本机移动应用程序(当前是 UWP、Android)使用,我正在尝试实现一种客户端可以使用用户名/密码和外部提供商(例如谷歌和脸书。现在我正在使用openIddict并且我ExternalProviderCallback必须返回本地令牌,我假设当前返回cookie!(我已经从某处复制了大部分代码)而且它似乎不是我认为正确的方法的 AuthorizationCodeFlow !

现在这是我的启动课程

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        if (env.IsDevelopment())
        {
            builder.AddUserSecrets();
        }
        builder.AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IConfiguration>(c => Configuration);
        services.AddEntityFramework();
        services.AddIdentity<ApplicationUser, IdentityRole>(config => …
Run Code Online (Sandbox Code Playgroud)

authentication google-authentication oauth-2.0 asp.net-core openiddict

1
推荐指数
1
解决办法
4274
查看次数

laravel 社交名流从谷歌授权码获取谷歌访问令牌

我有一个 Android 应用程序,它使用 google 身份验证来注册用户
,我正在使用它laravel socillite进行身份验证

我无法让它工作,因为 android 应用程序向我发送了授权代码而不是访问令牌,而且我不知道如何从中获取访问令牌根据Authorization Code
我的理解,我应该执行以下操作:

  • access token从 android获取Authorization Code
  • 用于Socialite::driver('google')->userFromToken($token)获取用户数据
  • 将令牌发送JWT到 Android 设备
    任何人都可以解释我如何使用laravel socillite

android google-authentication jwt laravel laravel-socialite

1
推荐指数
1
解决办法
3670
查看次数

无需 Oauth2 从 Youtube Analytics API 读取数据

我目前正在编写一个 python 脚本,用于从 YouTube Analytics API 中提取信息以获取单独的 YouTube 频道列表。例如,输出是统计上个月每个 YouTube 频道的视频观看次数。

我最初的想法是要求每个 YouTube 帐户所有者在其 console.cloud.google 中创建一个 YouTube Analytics 应用程序,创建一个项目,启用 youTube Analytics API,生成一个 API 密钥并指定 YouTube Analytics 需要它API。

我正在使用一个帐户进行测试,如果我尝试使用通过上述过程生成的 API 密钥运行脚本并进行身份验证,如下所示:

def get_service():
    return build('youtubeAnalytics', 'v2', developerKey=API_KEY)
Run Code Online (Sandbox Code Playgroud)

它失败了HttpError 401 Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

我不确定我在创建 API 密钥时是否做错了什么,或者 YouTube Analytics API 是否需要Oauth2 身份验证。如果是后者,那么我很惊讶谷歌控制台允许您一路生成 API 密钥并指定它们是 YouTube Analytics API 所需要的,结果却发现您无法使用它。

所以我的问题是:我是否必须使用 Oauth2 for YouTube Analytics …

youtube youtube-api google-authentication youtube-analytics youtube-analytics-api

1
推荐指数
1
解决办法
1188
查看次数

如何在 Python 中使用服务帐户凭据创建 Google 表格?

Service Account Credentials 我在这里创建并得到了 json key service.json

然后我尝试:

from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
credentials = service_account.Credentials.from_service_account_file(
        'service.json', scopes=SCOPES)

drive = build('drive', 'v3', credentials=credentials)
file_metadata = {
    'name': 'sampleName',
    'parents': ['#### folderId ###'],
    'mimeType': 'application/vnd.google-apps.spreadsheet',
}
res = drive.files().create(body=file_metadata).execute()
print(res)
Run Code Online (Sandbox Code Playgroud)

有错误:

<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "Insufficient Permission: Request had insufficient authentication scopes.">

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console" …
Run Code Online (Sandbox Code Playgroud)

python google-authentication google-drive-api google-console-developer google-sheets-api

1
推荐指数
1
解决办法
4595
查看次数

从客户端 ID + 秘密获取 Google 项目 ID?

我有一个客户端 ID 和客户端密钥,用于 Django 应用程序中的一些基于 Google 的身份验证。如何使用此信息获取正在使用的实际 Google 项目名称/ID?

使用 API 固然很棒,但我也不愿意点击一些 Web UI。

PS——我不确定如何标记/分类这个问题,所以我很感谢那里的任何帮助。

google-authentication google-cloud-platform

1
推荐指数
1
解决办法
1032
查看次数

在Localhost中测试LightOpenID

我正在使用LightOpenID在我的PHP Web应用程序中启用Google身份验证.

但是,当我在本地服务器上测试相同时,我收到以下错误

( ! ) Fatal error: Uncaught exception 'ErrorException' with message 'You must have either https wrappers or curl enabled.' in C:\wamp\www\speakerdb\openid.php on line 94
( ! ) ErrorException: You must have either https wrappers or curl enabled. in C:\wamp\www\speakerdb\openid.php on line 94
Call Stack
#   Time    Memory  Function    Location
1   0.0006  366848  {main}( )   ..\index.php:0
2   0.0034  648640  LightOpenID->__construct( ) ..\index.php:4
Run Code Online (Sandbox Code Playgroud)

这在我的远程服务器上运行良好.我将在我的应用程序的每个页面中使用LightOpenID来检查用户是否已登录.我尝试给"localhost"作为域名,但得到相同的错误.

我启用了curl而不是我的wamp服务器但是当启用curl时,带有LightOpenID的页面不会运行.

php openid wampserver google-authentication lightopenid

0
推荐指数
1
解决办法
2234
查看次数

如何使用OAuth2.0访问Google Feed(Reader)?

我想使用OAuth2.0访问Google Feed.我使用google-oauth-java-client获取访问令牌.如何使用它来访问feeds API?

我引用了dailymotion-cmdline-sample,并将SCOPE更改为http://www.google.com/reader/api获取凭据.

它返回:

401 Unauthorized

You must be signed in to access this stream.
Run Code Online (Sandbox Code Playgroud)

我不知道出了什么问题......

我还阅读了一些帖子,显示OAuth2.0可以完成这项工作,但它们对我来说不够详细:

仅对Google OAuth 2.0令牌具有读访问权限?

使用Google阅读器API

使用OAuth2 access_token访问Google阅读器订阅

java google-feed-api google-authentication oauth-2.0

0
推荐指数
1
解决办法
490
查看次数

Node.js 内存泄漏

我从谷歌加载我的日历。但每次我这样做时,节点都会多使用 2 MB 的内存。即使我删除了该模块。我需要每 5 或 10 分钟加载一次,以便查看是否有变化。这是我的代码。

google-calender.js 模块

module.exports = {

  loadCalendars: function(acces, res){
    gcal = require('google-calendar');
    google_calendar = new gcal.GoogleCalendar(acces);

    google_calendar.calendarList.list(function(err, calendarList) {

        toLoadCalenders = calendarList.items.length;
        loaded = 0;
        data = [];

        for(var i = 0; i < toLoadCalenders; i++){           
            google_calendar.events.list(calendarList.items[i].id, function(err, calendarList) {
                loaded++;
                data.push(calendarList);
                if (loaded == toLoadCalenders) {
                    res.send(data);
                }
            });

        }

    });
  }
}
Run Code Online (Sandbox Code Playgroud)

main.js

app.get('/google-calender', function (req, res) {
    google = require('./google-calender');
    google.loadCalendars(acces, res);

    setTimeout(function(){
        delete google;
    },500);
});
Run Code Online (Sandbox Code Playgroud)

有谁知道我如何防止内存泄漏?

memory-leaks google-authentication node.js

0
推荐指数
1
解决办法
1154
查看次数

使用OWIN验证ASP.NET MVC应用程序而无需登录gmail等

我得到了ASP.NET MVC应用程序,它通过OWIN库通过Google帐户验证用户.

用户有时会在主机(客户)计算机,公共计算机上登录Web应用程序来管理Web应用程序中的某些数据.

有一个登录按钮,可将您重定向到Google登录页面,用户输入用户名和密码,然后重定向回此Web应用程序.到目前为止,这是好的,这就是OWIN通常的工作方式.

我担心用户忘记注销应用程序而有人会从Web应用程序捕获数据.这在任何网络应用程序中都存在风险,我必须接受它.但是,如果用户忘记退出,则会有额外的风险,即有人会捕获来自Gmail,Google文档和所有相关Google服务的所有电子邮件.

我希望修改Owin身份验证,以便在Owin将用户重定向到Google登录页面后,Google只会将授权传递给Web应用,而无需登录用户访问Gmail以及Web浏览器中的所有相关Google服务.

以下代码也会登录Gmail作为Web应用程序身份验证的副作用.我看到OWIN有很多配置选项.我相信它是可以实现的:

public partial class Startup
{
    private double _expirationTimeCookies = 30; // minutes - sliding expiration

    public static ApplicationUserManager ApplicationUserManagerCreate(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
    {
        var userStore = new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>());
        var tokenProvider = new DataProtectorTokenProvider<ApplicationUser>(options.DataProtectionProvider.Create("ASP.NET Identity"));

        ApplicationUserManager manager = new ApplicationUserManager(userStore);

        manager.EmailService = new EmailService();
        manager.SmsService = new SmsService();

        var dataProtectionProvider = options.DataProtectionProvider;
        if (dataProtectionProvider != null)
        {
            manager.UserTokenProvider = tokenProvider;
        }

        return ApplicationUserManager.Create(tokenProvider, manager);
    }

    public void ConfigureAuth(IAppBuilder app)
    {           
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManagerCreate);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

        app.UseCookieAuthentication(new …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc google-authentication owin

0
推荐指数
1
解决办法
626
查看次数

Google Cloud 文本转语音 REST API 身份验证

所以我想通过我的 C++ 程序的简单 POST 请求来使用 Google Cloud Text to Speech,问题在于它们的身份验证。我确实按照他们提到的那样创建了一个服务帐户,并且获得了包含我的私钥的文件。但我不知道如何在我的 POST 请求中使用它来进行身份验证?

POST 网址:https://texttospeech.googleapis.com/v1beta1/text :synthesize 这是我的 POST 正文:

{ "audioConfig": { "audioEncoding": "LINEAR16", "pitch": "0.00", "speakingRate": "1.00" }, "input": { "text": "Hello World" }, "voice": { "languageCode": "en-US", "name": "en-US-Wavenet-E" } }

rest google-authentication google-text-to-speech

0
推荐指数
1
解决办法
2080
查看次数

ASP.NET Core 6 JWT 不记名令牌异常

我正在尝试使用 JWT 不记名令牌和谷歌身份验证来实现对 Web API 的身份验证。发现这个答案非常有帮助,但是当它成功验证时,我得到 500,但有以下例外:

System.NullReferenceException:未将对象引用设置为对象的实例。在 Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:错误:执行请求时发生未处理的异常。

System.NullReferenceException:未将对象引用设置为对象的实例。在 Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() 在 Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() 在 Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync() 在 Microsoft.AspNetCore.Authentication.AuthenticationService .AuthenticateAsync(HttpContext 上下文,字符串方案) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext 上下文)

当令牌无效时,我会收到 401 响应。

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options =>
        {
            options.AddDefaultPolicy(builder =>
            {
                builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
            });
        });

        services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(o =>
            {
                o.SecurityTokenValidators.Clear();
                o.SecurityTokenValidators.Add(
                    new GoogleTokenValidator(
                        client_id
                        ));
            });
        
        services.AddScoped<PhotoService>();
        services.AddScoped<TagService>();
        services.AddScoped(_ => new BlobServiceClient(Configuration.GetConnectionString("AzureBlobStorage")));
        services.AddDbContext<Data.DataContext>(x => x.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        services.AddControllers().AddJsonOptions(options =>
        { …
Run Code Online (Sandbox Code Playgroud)

c# google-authentication jwt bearer-token asp.net-core

0
推荐指数
1
解决办法
4826
查看次数

为什么在 php 项目中的 Nn.handleCredentialResponse [作为回调] 中没有定义decodeJwtResponse?

<body>
   <script src="https://accounts.google.com/gsi/client" async defer></script>
   <div id="g_id_onload"
     data-client_id="790854323959-v2lniefhl7ripoijm0ooetu9ari91g3q.apps.googleusercontent.com"
     data-callback="handleCredentialResponse">
   </div>
   <div class="g_id_signin" data-type="standard"></div>
  
   <script>
      function handleCredentialResponse(response) {
          // decodeJwtResponse() is a custom function defined by you
         // to decode the credential response.
         const responsePayload = decodeJwtResponse(response.credential);
         console.log("ID: " + responsePayload.sub);
         console.log('Full Name: ' + responsePayload.name);
         console.log('Given Name: ' + responsePayload.given_name);
         console.log('Family Name: ' + responsePayload.family_name);
         console.log("Image URL: " + responsePayload.picture);
         console.log("Email: " + responsePayload.email);
      }
   </script>
</body>
Run Code Online (Sandbox Code Playgroud)

注意:我想使用javascript将google登录集成到php项目中。但我收到类似错误 -decodeJwtResponse 未在 Nn.handleCredentialResponse [作为回调] 中定义。请帮助我,我想获得个人资料详细信息。请向我提供有关我的查询的所有详细信息。

javascript php google-authentication

0
推荐指数
1
解决办法
1278
查看次数