Announcement Announcement Module
Collapse
No announcement yet.
Spring OAuth2 M6 and Google Analytics: No OAuth 2 Security Context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    There's not much point sending me code to reproduce the problem (it's trivial once you have registered an app with Google). You can raise a JIRA if you like, but to do anything about it I think you would need to get some more information from Google as to why the token request is invalid (it seems to me to match their own documentation https://developers.google.com/accoun...Auth2WebServer). The most likely response from Google, assuming you can get anyone's attention, is that you should use the Google Java client APIs (which isn't a bad idea really and if you can get that to work we might be able to see the difference).

    Comment


    • #17
      Dave, thanks for the suggestion.

      I would try their code and see if there's much difference. It would be a good comparison exercise. I'm just surprise though that no one has tried integrating Google Analytics with Spring OAuth yet (or maybe someone hasn't posted or had any problems yet).

      I actually prefer to stick with Spring because it has simpler model, but then again just to see what's really happening I wouldn't mind to try their own code.

      Comment


      • #18
        Originally posted by skram View Post
        I'm just surprise though that no one has tried integrating Google Analytics with Spring OAuth yet (or maybe someone hasn't posted or had any problems yet).
        There was a post a few months back and it worked (eventually) then, I think - I remember the thing about the client authentication. Either my memory is bad, or they changed their server implementation (or both possibly).

        Comment


        • #19
          I think I cracked it. If you remove the state parameter from the token request (not sure why it was there in the first place) it reveals another problem, which is a redirect mismatch. I raised a JIRA for that (SECOAUTH-284) - should be fixed now.

          Comment


          • #20
            Thanks for the quick action.

            Unfortunately, I'm unable to pull RC1 or even the SNAPSHOTS. I'm able to pull SNAPSHOT builds for Spring Core, JPA, and etc. But this one is unpullable. Is there a special repo where this resides?

            This is what I use (along with Artifactory):
            Code:
            	
            	<repository>
            		<id>org.springframework.maven.release</id>
            		<name>Spring Maven Release Repository</name>
            		<url>http://maven.springframework.org/release</url>
            		<releases><enabled>true</enabled></releases>
            		<snapshots><enabled>false</enabled></snapshots>
            	</repository>
            
            	<repository>
            		<id>org.springframework.maven.snapshot</id>
            		<name>Spring Maven Snapshot Repository</name>
            		<url>http://maven.springframework.org/snapshot</url>
            		<releases><enabled>false</enabled></releases>
            		<snapshots><enabled>true</enabled></snapshots>
            	</repository>
            
            	<repository>
            		<id>org.springframework.maven.milestone</id>
            		<name>Spring Maven Milestone Repository</name>
            		<url>http://maven.springframework.org/milestone</url>
            		<snapshots><enabled>false</enabled></snapshots>
            	</repository>
            Update: Ok, I'm building the project now by downloading the project from GitHub
            Last edited by skram; Jun 11th, 2012, 09:25 PM.

            Comment


            • #21
              SUCCESS!!!

              I'm able to access my Google Analytics data now. Here's the JSON result (same result I got from Google's OAuth Playground):

              Code:
              {"message":["{\"kind\":\"analytics#gaData\",\"id\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXXX&metrics=ga:visits,ga:bounces&start-date=2009-04-20&end-date=2012-05-20&start-index=1&max-results=1000\",\"query\":{\"start-date\":\"2009-04-20\",\"end-date\":\"2012-05-20\",\"ids\":\"ga:XXXXXX\",\"metrics\":[\"ga:visits\",\"ga:bounces\"],\"start-index\":1,\"max-results\":1000},\"itemsPerPage\":1000,\"totalResults\":1,\"selfLink\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXX&metrics=ga:visits,ga:bounces&start-date=2009-04-20&end-date=2012-05-20&start-index=1&max-results=1000\",\"profileInfo\":{\"profileId\":\"XXXXXX\",\"accountId\":\"XXXXXX\",\"webPropertyId\":\"UA-XXXXXX-1\",\"internalWebPropertyId\":\"XXXXXX\",\"profileName\":\"skram\",\"tableId\":\"ga:XXXXXX\"},\"containsSampledData\":false,\"columnHeaders\":[{\"name\":\"ga:visits\",\"columnType\":\"METRIC\",\"dataType\":\"INTEGER\"},{\"name\":\"ga:bounces\",\"columnType\":\"METRIC\",\"dataType\":\"INTEGER\"}],\"totalsForAllResults\":{\"ga:visits\":\"409949\",\"ga:bounces\":\"292510\"},\"rows\":[[\"409949\",\"292510\"]]}"],"success":true}
              Just for the record, to resolve the issue, I upgraded to spring-security-oauth2 1.0.0.BUILD-SNAPSHOT (which is supposedly for RC1).

              Since the build is not available from the usual repositories, I had to download the source from GitHub at https://github.com/SpringSource/spring-security-oauth. Then I imported the project into STS (Eclipse). Then I run a mvn install -DskipTests (to bypass the test). I had m2eclipse installed with STS for easy Maven integration.

              For future readers, here's my Maven snippet:
              Code:
              	<dependency>
              		<groupId>org.springframework.security.oauth</groupId>
              		<artifactId>spring-security-oauth2</artifactId>
              		<version>1.0.0.BUILD-SNAPSHOT</version>
              	</dependency>
              spring-oauth.xml
              Code:
              <?xml version="1.0" encoding="UTF-8"?>
              <beans:beans xmlns="http://www.springframework.org/schema/security"
              	xmlns:beans="http://www.springframework.org/schema/beans"
              	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              	xmlns:context="http://www.springframework.org/schema/context"
              	xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
              	xsi:schemaLocation="http://www.springframework.org/schema/beans 
              		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              		http://www.springframework.org/schema/security 
              		http://www.springframework.org/schema/security/spring-security-3.1.xsd
              	   	http://www.springframework.org/schema/context
              	   	http://www.springframework.org/schema/context/spring-context-3.1.xsd
              		http://www.springframework.org/schema/security/oauth2 
              		http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd">
              	
              	<oauth:client id="oauth2AuthenticationClientFilter"/>
              	
              	<oauth:resource id="oauth-resource" 
              		client-authentication-scheme="form" 
              		type="authorization_code"
              		access-token-uri="https://accounts.google.com/o/oauth2/token" 
              		user-authorization-uri="https://accounts.google.com/o/oauth2/auth"
              		client-id="XXXXXX" 
              		client-secret="YYYYYY"
              		scope="https://www.googleapis.com/auth/analytics.readonly"
              		pre-established-redirect-uri="http://localhost:8080/myappgoogle/test"/>
              	 
              	 <oauth:rest-template id="oauth-rest-template" resource="oauth-resource"/>
              	
              </beans:beans>
              Controller
              Code:
              	@RequestMapping(value = "/test")
              	public @ResponseBody StatusResponse test() {
              			
              			String dataUri = "https://www.googleapis.com/analytics/v3/data/ga?" +
              			"ids=ga:XXXXXX&" +
              			"start-date=2009-04-20&" +
              			"end-date=2012-05-20&" +
              			"metrics=ga:visits,ga:bounces";
              			
              			ObjectNode result = oauth2RestTemplate.getForObject(dataUri, ObjectNode.class);
              
              			return new StatusResponse(true, result.toString());
              	}
              By the way, the GA data is taken from my blog at http://krams915.blogspot.com (Spring-related tutorial blog)

              Comment


              • #22
                @skram: you resolved it only by upgrading the spring-oauth version?
                this is very weird since I use RC2a and get similar error - I do get the code but cannot exchange it and get a token (the POST call to Google to get the token fails) and I get the same error from them "Invalid request"...

                EDIT:
                thanks to the configuration that @skram has used in front of Google, I've succeeded to make it run, too. I use this configuration
                Code:
                	<oauth:resource id="google" 
                		type="authorization_code" 
                		client-id="" 
                		client-secret=""
                		access-token-uri="https://accounts.google.com/o/oauth2/token" 
                		user-authorization-uri="https://accounts.google.com/o/oauth2/auth"
                		scope="http://www.google.com/reader/api/"
                		client-authentication-scheme="form"
                		pre-established-redirect-uri="https://ohad.sealdoc.com/oauth2-client/hello" />
                note the client-authentication-scheme is "form" and not as the default ("header"). This causes the client id and secret to be passed in the body instead of the header; it is supported by the spec but is not recommended... yet I could not make it work when I pass the creds in the headers :/
                Last edited by OhadR; Nov 8th, 2012, 06:07 AM.

                Comment

                Working...
                X