public function getOAuthAccessorProviderKey(ProviderKey $providerKey, ProviderInfo $provInfo) { if ($provInfo == null) { throw new OAuthNoDataException("must pass non-null provider info to getOAuthAccessor"); } //AccesorInfo $result = new AccesorInfo(); $result->setHttpMethod($provInfo->getHttpMethod()); $result->setParamLocation($provInfo->getParamLocation()); //ConsumerKeyAndSecret $key = md5(serialize($providerKey)); $consumerKeyAndSecret = null; if (isset($this->consumerInfos[$key])) { $consumerKeyAndSecret = $this->consumerInfos[$key]; } else { throw new OAuthNoDataException("The Key was invalid for consumerInfos, maybe your oauth.json configuration is wrong."); } if ($consumerKeyAndSecret == null) { if ($this->defaultConsumerKey == null || $this->defaultConsumerSecret == null) { throw new OAuthNoDataException("ConsumerKeyAndSecret was null in oauth store"); } else { $consumerKeyAndSecret = new ConsumerKeyAndSecret($this->defaultConsumerKey, $this->defaultConsumerSecret, OAuthStoreVars::$KeyType['RSA_PRIVATE']); } } //OAuthServiceProvider $oauthProvider = $provInfo->getProvider(); if (!isset($oauthProvider)) { throw new OAuthNoDataException("OAuthService provider was null in provider info"); } // Accesing the class $usePublicKeyCrypto = $consumerKeyAndSecret->getKeyType() == OAuthStoreVars::$KeyType['RSA_PRIVATE']; //OAuthConsumer $consumer = $usePublicKeyCrypto ? new OAuthConsumer($consumerKeyAndSecret->getConsumerKey(), null, $oauthProvider) : new OAuthConsumer($consumerKeyAndSecret->getConsumerKey(), $consumerKeyAndSecret->getConsumerSecret(), $oauthProvider); if ($usePublicKeyCrypto) { $consumer->setProperty(OAuthSignatureMethod_RSA_SHA1::$PRIVATE_KEY, $consumerKeyAndSecret->getConsumerSecret()); $result->setSignatureType(OAuthStoreVars::$SignatureType['RSA_SHA1']); } else { $result->setSignatureType(OAuthStoreVars::$SignatureType['HMAC_SHA1']); } $result->setAccessor(new OAuthAccessor($consumer)); return $result; }
/** * Reads OAuth provider information out of gadget spec. * @param spec * @return a GadgetInfo */ public static function getProviderInfo(GadgetSpec $spec, $serviceName) { $oauthSpec = $spec->oauth; if ($oauthSpec == null) { $message = "gadget spec is missing /ModulePrefs/OAuth section"; throw new GadgetException($message); } $service = null; if (isset($oauthSpec[$serviceName])) { $service = $oauthSpec[$serviceName]; } if ($service == null) { $message = ''; $message .= "Spec does not contain OAuth service '"; $message .= $serviceName; $message .= "'. Known services: "; foreach ($services as $key => $value) { $message .= "'"; $message .= $key; $message .= "'"; $message .= ", "; } throw new GadgetException($message); } $provider = new OAuthServiceProvider($service->getRequestUrl(), $service->getAuthorizationUrl(), $service->getAccessUrl()); $httpMethod = null; switch ($service->getRequestUrl()->method) { case "GET": $httpMethod = OAuthStoreVars::$HttpMethod['GET']; break; case "POST": default: $httpMethod = OAuthStoreVars::$HttpMethod['POST']; break; } $paramLocation = null; switch ($service->getRequestUrl()->location) { case OAuthStoreVars::$OAuthParamLocation['URI_QUERY']: case OAuthStoreVars::$OAuthParamLocation['POST_BODY']: case OAUthStoreVars::$OAuthParamLocation['AUTH_HEADER']: $paramLocation = $service->getRequestUrl()->location; break; default: $paramLocation = OAuthStoreVars::$OAuthParamLocation['AUTH_HEADER']; break; } $provInfo = new ProviderInfo(); $provInfo->setHttpMethod($httpMethod); $provInfo->setParamLocation($paramLocation); // TODO: for now, we'll just set the signature type to HMAC_SHA1 // as this will be ignored later on when retrieving consumer information. // There, if we find a negotiated HMAC key, we will use HMAC_SHA1. If we // find a negotiated RSA key, we will use RSA_SHA1. And if we find neither, // we may use RSA_SHA1 with a default signing key. $provInfo->setSignatureType(OAuthStoreVars::$SignatureType['HMAC_SHA1']); $provInfo->setProvider($provider); return $provInfo; }