title: OpenID+OAuth for YouTube using openid4java
body: <p>My application allows users to log in using OpenID from Google or Yahoo. There's also a feature which allows users to upload to YouTube. Some users arrive via a YouTube context with the purpose of creating something and uploading to YouTube. These users will need to authorize my application to access both the address on their Google Account via OpenID, and their YouTube account via OAuth. I'd like this to be achieved with a single authorization click for the user.</p>
  
  <p>I've seen this done here: <a href="http://www.youtube.com/create/Xtranormal" rel="nofollow noreferrer">http://www.youtube.com/create/Xtranormal</a>. The request sent to the Google OpenID endpoint from this app is: </p>
  
  <pre><code>https://accounts.google.com/o/openid2/auth?
  openid.ns=http://specs.openid.net/auth/2.0&amp;
  openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&amp;
  openid.identity=http://specs.openid.net/auth/2.0/identifier_select&amp;
  openid.return_to=http://www.xtranormal.com/social/openid/complete/?next%3Dhttp%253A%252F%252Fyoutube.xtranormal.com%252Fytmm%252Fauth_popup_done%252F%26janrain_nonce%3D2011-08-29T16%253A35%253A53ZW0VqRw&amp;
  openid.assoc_handle=AOQobUcMlV0Hmk431QROK27UegIYqYffiPeCuZ8gsB2x5ULYP0FXuoDZ&amp;
  openid.ax.mode=fetch_request&amp;
  openid.ax.required=ext0,ext1,ext2&amp;
  openid.ax.type.ext0=http://axschema.org/namePerson/first&amp;
  openid.ax.type.ext1=http://axschema.org/namePerson/last&amp;
  openid.ax.type.ext2=http://axschema.org/contact/email&amp;
  openid.mode=checkid_setup&amp;
  openid.ns.ax=http://openid.net/srv/ax/1.0&amp;
  openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0&amp;
  openid.ns.sreg=http://openid.net/extensions/sreg/1.1&amp;
  openid.oauth.consumer=www.xtranormal.com&amp;
  openid.oauth.scope=http://gdata.youtube.com/&amp;
  openid.realm=http://www.xtranormal.com/&amp;
  openid.sreg.optional=postcode,country,nickname,email,fullname 
  </code></pre>
  
  <p>All the other OpenID support on the application (which works well), is written with OpenID4Java. I've tried to create a similar request by implementing the tips in <a href="https://stackoverflow.com/questions/4069060/library-to-integrate-googles-oauth-openid-hybrid-in-java-web-app/4319375#4319375">This answer</a>, however, I can't for the life of me get the Google popup to ask me for YouTube, it only asks for the email address.</p>
  
  <p>I'm adding the parameters from the answer by adding this message extension:</p>
  
  <pre><code>public class OAuthHybridRequest implements MessageExtension{
      public static String SCOPE_YOUTUBE = "http://gdata.youtube.com/";
      ParameterList parameters;
      public OAuthHybridRequest(String scope){
          parameters = new ParameterList();
          parameters.set(new Parameter("consumer", DeploymentProperties.getDeploymentProperty("OAUTH_CONSUMER_KEY")));
          parameters.set(new Parameter("scope", scope));
      }   
      public ParameterList getParameters() {
          return parameters;
      }
      public String getTypeUri() {
          return "http://specs.openid.net/extensions/oauth/1.0";
      }
      ...
  }
  </code></pre>
  
  <p>Which makes my request look like this:</p>
  
  <pre><code>https://accounts.google.com/o/openid2/auth?
  openid.ns=http://specs.openid.net/auth/2.0&amp;
  openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&amp;
  openid.identity=http://specs.openid.net/auth/2.0/identifier_select&amp;
  openid.return_to=http://martin.test.example.no/socialdelegation/hybrid/youtube/sso/auth?is_callback%3Dtrue%26requestedURL%3D%252Fmovieeditor%252Fscripts%252Fpopupcloser.jsp&amp;
  openid.realm=http://martin.test.example.no&amp;
  openid.assoc_handle=AOQobUcMkuyp1pVZjpF-b8dVqTfB6Y6IyOZxihsk-XD1DOq0xv06lrlPgaJEF-ITUCdJiXPi&amp;
  openid.mode=checkid_setup&amp;
  openid.ns.ext1=http://specs.openid.net/extensions/oauth/1.0&amp;
  openid.ext1.consumer=test.example.no&amp;
  openid.ext1.scope=http://gdata.youtube.com&amp;
  openid.ns.sreg=http://openid.net/sreg/1.0&amp;
  openid.sreg.required=fullname,nickname,email&amp;
  openid.ns.ext3=http://openid.net/srv/ax/1.0&amp;
  openid.ext3.mode=fetch_request&amp;
  openid.ext3.type.email=http://axschema.org/contact/email&amp;
  openid.ext3.type.firstName=http://axschema.org/namePerson/first&amp;
  openid.ext3.type.lastName=http://axschema.org/namePerson/last&amp;
  openid.ext3.type.userName=http://axschema.org/namePerson/friendly&amp;
  openid.ext3.type.gender=http://axschema.org/person/gender&amp;
  openid.ext3.type.fullName=http://axschema.org/namePerson&amp;
  openid.ext3.required=email,firstName,lastName,userName,gender,fullName
  </code></pre>
  
  <p>What am I missing here?</p>