小编joh*_*yka的帖子

如何在 Spring OAuth2 客户端中获取刷新令牌

我正在开发一个 Spring 应用程序,它充当 OAuth2 客户端,Spotify 是资源服务器。这是我的配置:

spring:
  security:
    oauth2:
      client:
        registration:
          spotify:
            client-id: ...
            client-secret: ...
            authorization-grant-type: authorization_code
            redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
            scope: user-read-private, user-read-email
            client-name: Spotify
            client-alias: spotify
        provider:
          spotify:
            authorization-uri: https://accounts.spotify.com/authorize
            token-uri: https://accounts.spotify.com/api/token
            user-info-uri: https://api.spotify.com/v1/me
            user-name-attribute: display_name
Run Code Online (Sandbox Code Playgroud)

我的问题是我只是找不到如何获取 Spotify 在响应中发送的刷新令牌/api/token

Spotify 的响应如下所示:(来源: https: //developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow

Spotify 响应

我尝试CustomUserService像这样实现我自己的:

spring:
  security:
    oauth2:
      client:
        registration:
          spotify:
            client-id: ...
            client-secret: ...
            authorization-grant-type: authorization_code
            redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
            scope: user-read-private, user-read-email
            client-name: Spotify
            client-alias: spotify
        provider:
          spotify:
            authorization-uri: https://accounts.spotify.com/authorize
            token-uri: https://accounts.spotify.com/api/token
            user-info-uri: https://api.spotify.com/v1/me
            user-name-attribute: display_name …
Run Code Online (Sandbox Code Playgroud)

spring oauth-2.0 jwt

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

使用Nest在C#中进行Elasticsearch测试(单元/集成)最佳实践

我一直在搜索我应该如何测试我的数据访问层而不是很成功.让我列出我的担忧:

  1. 单元测试

这个人(这里:使用InMemoryConnection测试ElasticSearch)说:

虽然声明序列化形式的请求符合您在SUT中的期望可能就足够了.

断言请求的序列化形式是否真的值得?这些测试有什么价值吗?它似乎不太可能改变不应该更改序列化请求的函数.

如果值得,那么断言这些要求的正确方法是什么?

  1. 再次进行单元测试

另一个人(这里:使用MOQ的ElasticSearch 2.0 Nest Unit Testing)显示了一个好看的例子:

void Main()
{
    var people = new List<Person>
    {
        new Person { Id = 1 },
        new Person { Id = 2 },
    };

    var mockSearchResponse = new Mock<ISearchResponse<Person>>();
    mockSearchResponse.Setup(x => x.Documents).Returns(people);

    var mockElasticClient = new Mock<IElasticClient>();
    mockElasticClient.Setup(x => x
        .Search(It.IsAny<Func<SearchDescriptor<Person>, ISearchRequest>>()))
        .Returns(mockSearchResponse.Object);

    var result = mockElasticClient.Object.Search<Person>(s => s);

    Assert.AreEqual(2, result.Documents.Count()).Dump();
}

public class Person
{
    public int Id { get; set;}
}
Run Code Online (Sandbox Code Playgroud)

可能我错过了一些东西,但我看不出这段代码的重点.首先,他嘲笑一个 …

testing elasticsearch nest

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

标签 统计

elasticsearch ×1

jwt ×1

nest ×1

oauth-2.0 ×1

spring ×1

testing ×1