Author: [email protected] Date: Tue Sep 20 15:55:09 2011 New Revision: 1402 Log: Added initial OpenID client
Added: sandbox/ivol/openid-client/ sandbox/ivol/openid-client/pom.xml sandbox/ivol/openid-client/src/ sandbox/ivol/openid-client/src/main/ sandbox/ivol/openid-client/src/main/java/ sandbox/ivol/openid-client/src/main/java/org/ sandbox/ivol/openid-client/src/main/java/org/amdatu/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/OpenIDClient.java sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/osgi/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/osgi/Activator.java sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDClientImpl.java sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDRestServiceImpl.java sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/WebResourceProvider.java sandbox/ivol/openid-client/src/main/resources/ sandbox/ivol/openid-client/src/main/resources/jsp/ sandbox/ivol/openid-client/src/main/resources/jsp/openidlogin.jsp Added: sandbox/ivol/openid-client/pom.xml ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/pom.xml Tue Sep 20 15:55:09 2011 @@ -0,0 +1,217 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License.verning permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.amdatu.auth</groupId> + <artifactId>org.amdatu.auth</artifactId> + <version>0.2.1-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.auth.openid.client</artifactId> + <packaging>bundle</packaging> + <name>Amdatu Auth - OpenID client</name> + <description>Provides OpenID authentication.</description> + + <dependencies> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.dispatcher</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.httpcontext</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.jsp</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.resource</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.web</groupId> + <artifactId>org.amdatu.web.jaxrs</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.listener</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.application</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.persistencemanager</artifactId> + <type>bundle</type> + </dependency> + + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.listener</artifactId> + <type>bundle</type> + <version>0.2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.application</artifactId> + <type>bundle</type> + <version>0.2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.amdatu.cassandra</groupId> + <artifactId>org.amdatu.cassandra.persistencemanager</artifactId> + <type>bundle</type> + <version>0.2.0</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20090211</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.openid4java</groupId> + <artifactId>openid4java-nodeps</artifactId> + <version>0.9.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.3</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.nekohtml</groupId> + <artifactId>nekohtml</artifactId> + <version>1.9.14</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> + <scope>compile</scope> + </dependency> +<dependency> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + <version>1.3.03</version> + <scope>compile</scope> +</dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-Activator>org.amdatu.auth.openid.client.osgi.Activator</Bundle-Activator> + <Bundle-SymbolicName>org.amdatu.auth.openid.client</Bundle-SymbolicName> + <Embed-Dependency>*;scope=compile</Embed-Dependency> + <Export-Package> + org.amdatu.auth.openid.client, + </Export-Package> + <Private-Package> + org.openid4java, + org.openid4java.*, + org.apache.commons.httpclient, + org.apache.commons.httpclient.*, + org.apache.commons.codec, + org.apache.commons.codec.*, + org.apache.commons.logging, + org.apache.commons.logging.*, + org.apache.xerces.*, + org.cyberneko.html, + org.cyberneko.html.*, + org.apache.html.dom, + org.apache.wml, + org.apache.wml.dom, + org.apache.xml.serialize, + org.amdatu.auth.openid.client.osgi, + org.amdatu.auth.openid.client.service, + </Private-Package> + <Import-Package> + !net.sf.ehcache, + !org.apache.avalon.*, + !org.apache.axiom.*, + !org.apache.log, + !org.apache.log4j, + !org.apache.xml.resolver, + !org.apache.xml.resolver.readers, + !org.eclipse.higgins.*, + !org.openxri.*, + !org.springframework.*, + !sun.*, + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <!-- Profile that will copy the jar to the configured amdatu.deploy.directory when + the deploy profile is activated --> + <id>deploy</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <build> + <defaultGoal>install</defaultGoal> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> Added: sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/OpenIDClient.java ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/OpenIDClient.java Tue Sep 20 15:55:09 2011 @@ -0,0 +1,14 @@ +package org.amdatu.auth.openid.client; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openid4java.discovery.Identifier; + +public interface OpenIDClient { + String authRequest(String userSuppliedString, HttpServletRequest httpReq, HttpServletResponse httpResp) throws IOException; + + Identifier verifyResponse(HttpServletRequest httpReq); +} Added: sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/osgi/Activator.java ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/osgi/Activator.java Tue Sep 20 15:55:09 2011 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.amdatu.auth.openid.client.osgi; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.amdatu.auth.openid.client.OpenIDClient; +import org.amdatu.auth.openid.client.service.OpenIDClientImpl; +import org.amdatu.auth.openid.client.service.OpenIDRestServiceImpl; +import org.amdatu.auth.openid.client.service.WebResourceProvider; +import org.amdatu.web.dispatcher.DispatcherService; +import org.amdatu.web.httpcontext.ResourceProvider; +import org.amdatu.web.jsp.JspSupport; +import org.amdatu.web.resource.ResourceSupport; +import org.amdatu.web.rest.jaxrs.RESTService; +import org.apache.felix.dm.DependencyActivatorBase; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public class Activator extends DependencyActivatorBase { + /** + * Context id of the Authorization HTTP Context. + */ + public static final String CONTEXTID = "amdatu-authorization"; + + /** + * URL alias hosting the login gadget. + */ + public static final String ALIAS = "/openid"; + + /** + * URL alias hosting the JSPs. + */ + public static final String JSP_ALIAS = ALIAS + "/jsp"; + + /** + * URL alias hosting the statics. + */ + public static final String RES_ALIAS = ALIAS + "/static"; + + @Override + public void init(BundleContext context, DependencyManager manager) throws Exception { + manager.add( + createComponent() + .setInterface(OpenIDClient.class.getName(), null) + .setImplementation(OpenIDClientImpl.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true))); + + Dictionary<String, Object> properties = new Hashtable<String, Object>(); + properties.put(DispatcherService.CONTEXT_ID_KEY, CONTEXTID); + properties.put(JspSupport.JSP_ALIAS_KEY, JSP_ALIAS); + properties.put(ResourceSupport.RESOURCE_ALIAS_KEY, RES_ALIAS); + + manager.add(createComponent().setInterface(ResourceProvider.class.getName(), properties) + .setImplementation(WebResourceProvider.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true))); + + // Create and register the REST gadget management service + manager.add( + createComponent() + .setInterface(new String[] {RESTService.class.getName()}, null) + .setImplementation(OpenIDRestServiceImpl.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true)) + .add(createServiceDependency().setService(OpenIDClient.class).setRequired(true))); + } + + @Override + public void destroy(BundleContext context, DependencyManager manager) throws Exception { + } +} Added: sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDClientImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDClientImpl.java Tue Sep 20 15:55:09 2011 @@ -0,0 +1,133 @@ +package org.amdatu.auth.openid.client.service; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.amdatu.auth.openid.client.OpenIDClient; +import org.openid4java.OpenIDException; +import org.openid4java.consumer.ConsumerException; +import org.openid4java.consumer.ConsumerManager; +import org.openid4java.consumer.VerificationResult; +import org.openid4java.discovery.DiscoveryInformation; +import org.openid4java.discovery.Identifier; +import org.openid4java.message.AuthRequest; +import org.openid4java.message.AuthSuccess; +import org.openid4java.message.ParameterList; +import org.openid4java.message.ax.AxMessage; +import org.openid4java.message.ax.FetchRequest; +import org.openid4java.message.ax.FetchResponse; +import org.osgi.service.log.LogService; + +public class OpenIDClientImpl implements OpenIDClient { + private volatile LogService m_logService; + private volatile ConsumerManager manager; + + public OpenIDClientImpl() throws ConsumerException { + // instantiate a ConsumerManager object + manager = new ConsumerManager(); + } + + public void start() throws ConsumerException { + m_logService.log(LogService.LOG_INFO, "OpenID client started."); + } + + + // --- placing the authentication request --- + public String authRequest(String userSuppliedString, + HttpServletRequest httpReq, + HttpServletResponse httpResp) + throws IOException { + try { + // configure the return_to URL where your application will receive + // the authentication responses from the OpenID provider + String returnToUrl = "http://localhost:3737/rest/openid/callback"; + + // --- Forward proxy setup (only if needed) --- + // ProxyProperties proxyProps = new ProxyProperties(); + // proxyProps.setProxyName("proxy.example.com"); + // proxyProps.setProxyPort(8080); + // HttpClientFactory.setProxyProperties(proxyProps); + + // perform discovery on the user-supplied identifier + List discoveries = manager.discover(userSuppliedString); + + // attempt to associate with the OpenID provider + // and retrieve one service endpoint for authentication + DiscoveryInformation discovered = manager.associate(discoveries); + + // store the discovery information in the user's session + httpReq.getSession().setAttribute("openid-disc", discovered); + + // obtain a AuthRequest message to be sent to the OpenID provider + AuthRequest authReq = manager.authenticate(discovered, returnToUrl); + + // Attribute Exchange example: fetching the 'email' attribute + FetchRequest fetch = FetchRequest.createFetchRequest(); + fetch.addAttribute("email", + // attribute alias + "http://schema.openid.net/contact/email", // type URI + true); // required + + // attach the extension to the authentication request + authReq.addExtension(fetch); + + // Option 1: GET HTTP-redirect to the OpenID Provider endpoint + // The only method supported in OpenID 1.x + // redirect-URL usually limited ~2048 bytes + + return authReq.getDestinationUrl(true); + + } + catch (OpenIDException e) { + // present error to the user + } + + return null; + } + + // --- processing the authentication response --- + public Identifier verifyResponse(HttpServletRequest httpReq) { + try { + // extract the parameters from the authentication response + // (which comes in as a HTTP request from the OpenID provider) + ParameterList response = + new ParameterList(httpReq.getParameterMap()); + + // retrieve the previously stored discovery information + DiscoveryInformation discovered = (DiscoveryInformation) httpReq.getSession().getAttribute("openid-disc"); + + // extract the receiving URL from the HTTP request + StringBuffer receivingURL = httpReq.getRequestURL(); + String queryString = httpReq.getQueryString(); + if (queryString != null && queryString.length() > 0) + receivingURL.append("?").append(httpReq.getQueryString()); + + // verify the response; ConsumerManager needs to be the same + // (static) instance used to place the authentication request + VerificationResult verification = manager.verify( + receivingURL.toString(), + response, discovered); + + // examine the verification result and extract the verified identifier + Identifier verified = verification.getVerifiedId(); + if (verified != null) { + AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse(); + if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { + FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX); + List emails = fetchResp.getAttributeValues("email"); + String email = (String) emails.get(0); + } + + return verified; // success + } + } + catch (OpenIDException e) { + // present error to the user + } + + return null; + } +} Added: sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDRestServiceImpl.java ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/OpenIDRestServiceImpl.java Tue Sep 20 15:55:09 2011 @@ -0,0 +1,94 @@ +package org.amdatu.auth.openid.client.service; + +import java.io.IOException; +import java.net.URI; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.amdatu.auth.openid.client.OpenIDClient; +import org.amdatu.web.rest.jaxrs.RESTService; +import org.openid4java.consumer.ConsumerException; +import org.openid4java.discovery.Identifier; +import org.osgi.service.log.LogService; + +@Path("openid") +public class OpenIDRestServiceImpl implements RESTService { + // HTTP caching for this REST interface + protected static CacheControl NO_CACHE_CONTROL; + static { + NO_CACHE_CONTROL = new CacheControl(); + NO_CACHE_CONTROL.setNoCache(true); // No cache + } + + private static CacheControl MAXAGE_CACHE_CONTROL; + static { + MAXAGE_CACHE_CONTROL = new CacheControl(); + MAXAGE_CACHE_CONTROL.setMaxAge(300); // 5 minutes + } + + private LogService m_logService; + private OpenIDClient m_openIDClient; + + public void start() throws ConsumerException { + m_logService.log(LogService.LOG_INFO, "OpenID REST client started."); + } + + @GET + @Path("status") + @Produces({MediaType.TEXT_PLAIN}) + public String status() { + return "OpenID login service online"; + } + + @POST + @Path("login") + @Consumes("application/x-www-form-urlencoded") + public Response login(@Context final HttpServletRequest request, + @Context final HttpServletResponse response, @FormParam("uri") final String uri) { + try { + String redirect = m_openIDClient.authRequest(uri, request, response); + return Response.status(278).header("redirecturi", redirect).cacheControl(NO_CACHE_CONTROL).build(); + } + catch (IOException e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + + @GET + @Path("callback") + public Response getCallback(@Context final HttpServletRequest request) { + try { + Identifier identity = m_openIDClient.verifyResponse(request); + URI redirectUrl = new URI("http://localhost:3737/openid/jsp/src/openidlogin.jsp?identity=" + identity.getIdentifier()); + return Response.status(302).location(redirectUrl).cacheControl(NO_CACHE_CONTROL).build(); + } + catch (Exception e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } + + @POST + @Path("callback") + public Response postCallback(@Context final HttpServletRequest request) { + try { + Identifier identity = m_openIDClient.verifyResponse(request); + URI redirectUrl = new URI("http://localhost:3737/openid/jsp/src/openidlogin.jsp?identity=" + identity.getIdentifier()); + return Response.status(302).location(redirectUrl).cacheControl(NO_CACHE_CONTROL).build(); + } + catch (Exception e) { + throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); + } + } +} Added: sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/WebResourceProvider.java ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/java/org/amdatu/auth/openid/client/service/WebResourceProvider.java Tue Sep 20 15:55:09 2011 @@ -0,0 +1,44 @@ +package org.amdatu.auth.openid.client.service; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +import org.amdatu.auth.openid.client.osgi.Activator; +import org.amdatu.web.httpcontext.ResourceProvider; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public class WebResourceProvider implements ResourceProvider { + private static final String LOCAL_DEV_DIR = "D:\\Amdatu-svn\\sandbox\\ivol\\openid-client\\src\\main\\resources\\jsp\\"; + + // Service dependencies, injected by the Felix dependency manager + private volatile LogService m_logService; + private volatile BundleContext m_bundleContext; + + /** + * The init() method is invoked by the Felix dependency manager. + */ + public void start() { + m_logService.log(LogService.LOG_INFO, getClass().getName() + " service started"); + } + + public URL getResource(final String name) { + final String pathPrefix = Activator.ALIAS + "/"; + if (name != null && name.startsWith(pathPrefix)) { + if (name.contains("/src/")) { + String fileName = name.substring(name.lastIndexOf("/src/") + "/src/".length()); + File file = new File(LOCAL_DEV_DIR + fileName); + try { + return file.toURL(); + } + catch (MalformedURLException e) { + } + } + return m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length())); + } + return null; + + + } +} Added: sandbox/ivol/openid-client/src/main/resources/jsp/openidlogin.jsp ============================================================================== --- (empty file) +++ sandbox/ivol/openid-client/src/main/resources/jsp/openidlogin.jsp Tue Sep 20 15:55:09 2011 @@ -0,0 +1,139 @@ +<%-- + Copyright (c) 2010, 2011 The Amdatu Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License.verning permissions and limitations + under the License. +--%> + +<%@ page language="java" session="false" buffer="none" %> + +<c:set var="contextPath" value="${pageContext.request.contextPath}"/> +<c:set var="surveyUrl" value="${baseUrl}/rest/survey"/> + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>OpenID login</title> + <script type="text/javascript" src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script> + </head> + + <body> + <h3>Select your favorite OpenID provider</h3> + <p> + <table border="1"> + <tr> + <td> + <a href="#" onclick="javascript:login('google');"> + <img src="http://www.wilmakarels.nl/images/image/picasa/google-photo/google-photo.jpg" width="200px"/> + </a> + </td> + <td onclick="javascript:login('yahoo');"> + <a href="#" onclick="javascript:login('yahoo');"> + <img src="http://www.networking4all.com/img/gallery/news/yahoo.jpg" width="200px" /> + </a> + </td> + <td> + <a href="#" onclick="javascript:login('novell');"> + <img src="http://aleksspirkoski.files.wordpress.com/2011/09/novell.gif" width="200px" /> + </a> + </td> + </tr> + <tr> + <td> + <a href="#" onclick="javascript:login('hyves');"> + <img src="http://2.bp.blogspot.com/--oZl8IH-ujg/TZMLS5HTDrI/AAAAAAAAAOw/Vcb4znQdPv0/s1600/Hyves.png" width="200px" /> + </a> + </td> + <td> + <a href="#" onclick="javascript:login('myid');"> + <img src="http://r.myid.net/v1/images/share/logo.gif" width="200px" /> + </a> + </td> + <td> + <a href="#" onclick="javascript:login('myopenid');"> + <img src="http://michaelweisser.com/images/new_myopenid_logo_header.png" width="200px" /> + </a> + </td> + </tr> + <tr> + <td> + <a href="#" onclick="javascript:login('myspace');"> + <img src="http://www.deedeeyork.com/wp-admin/images/icons/myspace.gif" width="200px" /> + </a> + </td> + </tr> + </table> + </p> + + </body> +</html> + +<script type="text/javascript"> + var googleUri = "https://www.google.com/accounts/o8/id"; + var yahooUri = "https://me.yahoo.com"; + var novellUri = "http://www.novell.com/openid/"; + var hyvesUri = "http://www.hyves.nl/"; + var myidUri = "https://myid.net/"; + var myopenidUri = "https://myopenid.com/"; + var myspaceuri = "https://api.myspace.com/openid"; + + function login(openIdProvider) { + var openIdUri; + if (openIdProvider == "google") { + openIdUri = googleUri; + } + else if (openIdProvider == "yahoo") { + openIdUri = yahooUri; + } + else if (openIdProvider == "novell") { + openIdUri = novellUri; + } + else if (openIdProvider == "hyves") { + openIdUri = hyvesUri; + } + else if (openIdProvider == "myid") { + openIdUri = myidUri; + } + else if (openIdProvider == "myopenid") { + myopenidUri = novellUri; + } + else if (openIdProvider == "myspace") { + openIdUri = myspaceuri; + } + + var postdata = { + uri: openIdUri + }; + + var url = "/rest/openid/login"; + jQuery.ajax({ + url: url, + type: "POST", + data: postdata, + dataType: "json", + async:true, + success: function(data, textStatus, xhr) { + if (xhr.status == 278) { + var redirectUri = xhr.getResponseHeader("redirecturi"); + window.location.href = redirectUri; + //window.location.href = xhr.replace(/\?.*$/, "?next="+window.location.pathname); + } + }, + + + } + ); + } + +</script> _______________________________________________ Amdatu-commits mailing list [email protected] http://lists.amdatu.org/mailman/listinfo/amdatu-commits
