Google consent screen not shown as expected

后端 未结 3 1857
眼角桃花
眼角桃花 2020-12-21 12:15

I have registered a web application at cloud.google.com. \"The OAuth 2.0 Client ID\" looks like this: \"enter

3条回答
  •  粉色の甜心
    2020-12-21 12:46

    https://github.com/manishkbharti/grailsOauthPluginDemo already update the way to use Oauth2 for google. If you can't use Oauth2 from this Demo, you can look at grails plugin: Google for Spring Security OAuth plugin (https://github.com/donbeave/grails-spring-security-oauth-google). In their source code, they try to implement Oauth2 from DefaultApi20 class

    I don't know why but I can only get the authorization code after the process, so I need to do an extra step to convert this code to an access token, here is the code in details:

    def oauth2callback = { def code = params.code

        HttpTransport transport = new NetHttpTransport();
        JacksonFactory jsonFactory = new JacksonFactory();
        String CLIENT_ID = "....";
        String CLIENT_SECRET = "....";
        String REDIRECT_URI = ".....";
    
        GoogleTokenResponse response =
            new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, code, REDIRECT_URI).execute();
    
        GoogleCredential credential = new GoogleCredential.Builder().setClientSecrets(CLIENT_ID, CLIENT_SECRET)
                .setJsonFactory(jsonFactory).setTransport(transport).build()
                .setAccessToken(response.getAccessToken()).setRefreshToken(response.getRefreshToken());
    
        SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
        service.setOAuth2Credentials(credential);
        // Define the URL to request.  This should never change.
        URL SPREADSHEET_FEED_URL = new URL(
                "https://spreadsheets.google.com/feeds/spreadsheets/private/full");
    
        // Make a request to the API and get all spreadsheets.
        SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
        List spreadsheets = feed.getEntries();
    
        spreadsheets.each {
            println it.getTitle().getPlainText()
        }
    }
    

提交回复
热议问题