3

私は絶対にGoogleガイドに手紙を書き、Googleと統合するためのストームパスガイドに手紙を書きました。

これで、ユーザーは Google で正常にサインインできますが、Google から取得した認証コードを使用して Stormpath アカウント オブジェクトを取得しようとすると、Stormpath はこの行で例外をスローします。

ProviderAccountResult result = application.getAccount(request);

コード スニペットは次のとおりです。

public static Account getAccount(String codeOrToken, AuthType authType){
    try{
        if(getDirectory() != null){
            ProviderAccountRequest request = null;
            switch(authType){
                case AUTH_CODE: 
                    request = Providers.GOOGLE.account().setCode(codeOrToken).build(); 
                    break;
                case ACCESS_TOKEN: 
                    request = Providers.GOOGLE.account().setAccessToken(codeOrToken).build(); 
                    break;
                default: 
                    break;
            }
            Application application = AuthUtil.getApplication();
            ProviderAccountResult result = application.getAccount(request);
            Account account = result.getAccount();
            account.getCustomData().put("isNew", result.isNewAccount());
            return account;
        }
    }catch(Exception ex){
        ex.printStackTrace();
    }
    return null;
}

そして、これが Exception StackTrace です。

16:45:02,170 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) com.stormpath.sdk.resource.ResourceException: HTTP 400, Stormpath 7200 (http://docs.stormpath.com/errors/7200): Stormpath was not able to complete the request to Google: this can be caused by either a bad Google directory configuration, or the provided account credentials are not valid. Google error message: 400 Bad Request
16:45:02,172 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultDataStore.execute(DefaultDataStore.java:492)

16:45:02,173 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultDataStore.access$000(DefaultDataStore.java:67)

16:45:02,174 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultDataStore$2.filter(DefaultDataStore.java:390)

16:45:02,175 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:47)

16:45:02,176 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.ProviderAccountResultFilter.filter(ProviderAccountResultFilter.java:31)

16:45:02,177 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,178 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.api.ApiKeyQueryFilter.filter(ApiKeyQueryFilter.java:74)

16:45:02,180 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,181 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.cache.WriteCacheFilter.filter(WriteCacheFilter.java:80)

16:45:02,184 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,184 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.cache.ReadCacheFilter.filter(ReadCacheFilter.java:62)

16:45:02,185 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,186 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.api.DecryptApiKeySecretFilter.filter(DecryptApiKeySecretFilter.java:62)

16:45:02,187 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,188 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.EnlistmentFilter.filter(EnlistmentFilter.java:42)

16:45:02,189 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52)

16:45:02,189 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultDataStore.save(DefaultDataStore.java:411)

16:45:02,190 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.ds.DefaultDataStore.create(DefaultDataStore.java:322)

16:45:02,191 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.provider.ProviderAccountResolver.resolveProviderAccount(ProviderAccountResolver.java:46)

16:45:02,192 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at com.stormpath.sdk.impl.application.DefaultApplication.getAccount(DefaultApplication.java:325)

16:45:02,193 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at ng.ajo.socials.Google.getAccount(Google.java:79)

16:45:02,193 ERROR [stderr] (http-localhost-127.0.0.1-8080-5)   at ng.ajo.server.SocialsServlet.doPost(SocialsServlet.java:81)

//... The rest omitted for brevity

私は何が間違っているのか、この問題の解決策は何ですか?

編集:

これがより多くのコンテキストを提供するのに役立つ場合は、Google ディレクトリを作成する方法を次に示します。

public class Google {

    public static Directory getDirectory(){
        try{
            Directory directory = DirectoryUtil.getGoogleDirectory();

            //if the google directory does not exist CREATE it
            if(directory == null){
                Client client = AuthUtil.getClient();
                directory = client.instantiate(Directory.class);
                directory.setName(dirName);
                directory.setDescription(dirDescription);

                CreateDirectoryRequest request = Directories.newCreateRequestFor(directory)
                            .forProvider(Providers.GOOGLE.builder()
                                    .setClientId(appID)
                                    .setClientSecret(appSecret)
                                    .setRedirectUri(redirectURI)
                                    .build()
                            ).build();

                Tenant tenant = client.getCurrentTenant();
                directory = tenant.createDirectory(request);
                Application application = AuthUtil.getApplication();
                application.addAccountStore(directory.getHref());
            }

            return directory;

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

そして、Stormpath Web コンソールにログインすると、ディレクトリが作成され、すべての構成が配置された状態で実際に存在することがわかります...これですべてが機能するはずですが、機能しません...まだ混乱しています!

4

1 に答える 1