/* * eXist Open Source Native XML Database * Copyright (C) 2012 The eXist Project * http://exist-db.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * $Id$ */ package org.exist.security.realm.oauth; import org.scribe.builder.api.DefaultApi20; import org.scribe.model.OAuthConfig; import org.scribe.model.Verb; import org.scribe.utils.OAuthEncoder; import org.scribe.utils.Preconditions; /** * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a> * */ public class Google2Api extends DefaultApi20 { private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s"; private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; @Override public String getAccessTokenEndpoint() { return "https://accounts.google.com/o/oauth2/token";//?grant_type=authorization_code"; } @Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions .checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Google does not support OOB"); String scope = "https://www.googleapis.com/auth/userinfo.profile"; //config.getScope(); return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(scope) ); } public Verb getAccessTokenVerb() { return Verb.POST; } }