0

在 application.properties 我需要设置 OAuth2 密钥...

OAuth2AppClientId=AB............................AN

OAuth2AppClientSecret=br................................u8

OAuth2AppRedirectUri=http://localhost:8085/oauth2redirect

最初,我将键放在 "" 引号中,假设它们应该被视为字符串,但为了使其正常工作,我必须删除它们。有人可以解释发生了什么吗

OAuth2AppClientId=AB............................AN when I build the app 

以及如何了解有关 OAuth2AppClientId 的更多信息?

4

2 回答 2

0

如果您想查看如何编写代码来加载它,它只是应用程序内部使用的一个属性

OAuth2PlatformClientFactory

@Service
@PropertySource(value="classpath:/application.properties", ignoreResourceNotFound=true)
public class OAuth2PlatformClientFactory {

    @Autowired
    org.springframework.core.env.Environment env;

    OAuth2PlatformClient client;
    OAuth2Config oauth2Config;

    @PostConstruct
    public void init() {
        // intitialize a single thread executor, this will ensure only one thread processes the queue
        oauth2Config = new OAuth2Config.OAuth2ConfigBuilder(env.getProperty("OAuth2AppClientId"), env.getProperty("OAuth2AppClientSecret")) //set client id, secret
                .callDiscoveryAPI(Environment.SANDBOX) // call discovery API to populate urls
                .buildConfig();
        client  = new OAuth2PlatformClient(oauth2Config);
    }


    public OAuth2PlatformClient getOAuth2PlatformClient()  {
        return client;
    }

    public OAuth2Config getOAuth2Config()  {
        return oauth2Config;
    }

    public String getPropertyValue(String propertyName) {
        return env.getProperty(propertyName);
    }

}

https://github.com/IntuitDeveloper/OAuth2-JavaWithSDK/blob/master/src/main/java/com/intuit/developer/sampleapp/oauth2/client/OAuth2PlatformClientFactory.java

于 2020-03-26T13:41:41.290 回答
0

谷歌搜索可能是从这里开始的地方。这是关于什么Client IDClient Secret是的一个很好的资源:

我引用:

  • The client_id is a public identifier for apps.
  • The client_secret is a secret known only to the application and the authorization server.

Intuit 还有大量关于 OAuth2 以及如何实现它的文档。你应该阅读它:

总之,这Client ID就是 Intuit 如何识别您的应用程序正在尝试连接到 QuickBooks。当您构建/编译应用程序时,字符串没有“发生” - 这很正常string。但是,当您的应用程序针对 QuickBooks Online 进行身份验证时,您的应用程序会将其发送Client ID到 QuickBooks,以便 QuickBooks 知道是您的应用程序尝试授权与 QuickBooks 的连接,而不是其他某个应用程序。

于 2020-03-26T13:34:09.043 回答