From c1a810ba8d50d939f5a3e726185b1b7df8ba5a7f Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Wed, 25 Dec 2013 17:07:16 +0200 Subject: [PATCH] Documentation at "yii\authclient" updated. --- extensions/yii/authclient/README.md | 55 +++++++++++++++++++++- extensions/yii/authclient/clients/Facebook.php | 34 +++++++++++++ extensions/yii/authclient/clients/GitHub.php | 18 +++++++ extensions/yii/authclient/clients/GoogleOAuth.php | 18 +++++++ extensions/yii/authclient/clients/GoogleOpenId.php | 16 +++++++ extensions/yii/authclient/clients/LinkedIn.php | 34 +++++++++++++ extensions/yii/authclient/clients/Twitter.php | 34 +++++++++++++ extensions/yii/authclient/clients/YandexOAuth.php | 18 +++++++ extensions/yii/authclient/clients/YandexOpenId.php | 16 +++++++ .../yii/authclient/widgets/assets/authchoice.js | 11 +++++ 10 files changed, 253 insertions(+), 1 deletion(-) diff --git a/extensions/yii/authclient/README.md b/extensions/yii/authclient/README.md index b4c57ae..5aff122 100644 --- a/extensions/yii/authclient/README.md +++ b/extensions/yii/authclient/README.md @@ -27,4 +27,57 @@ to the require section of your composer.json. Usage & Documentation --------------------- -This extension... \ No newline at end of file +This extension provides the ability of the authentication via external credentials providers. +It covers OpenID, OAuth1 and OAuth2 protocols. + +You need to setup auth client collection application component: + +``` +'components' => [ + 'authClientCollection' => [ + 'class' => 'yii\authclient\Collection', + 'clients' => [ + 'google' => [ + 'class' => 'yii\authclient\clients\GoogleOpenId' + ], + 'facebook' => [ + 'class' => 'yii\authclient\clients\Facebook', + 'clientId' => 'facebook_client_id', + 'clientSecret' => 'facebook_client_secret', + ], + ], + ] + ... +] +``` + +Then you need to apply [[yii\authclient\AuthAction]] to some of your web controllers: + +``` +class SiteController extends Controller +{ + public function actions() + { + return [ + 'auth' => [ + 'class' => 'yii\authclient\AuthAction', + 'successCallback' => [$this, 'successCallback'], + ], + ] + } + + public function successCallback($client) + { + $atributes = $client->getUserAttributes(); + // user login or signup comes here + } +} +``` + +You may use [[yii\authclient\widgets\Choice]] to compose auth client selection: + +``` + ['site/auth'] +]); ?> +``` \ No newline at end of file diff --git a/extensions/yii/authclient/clients/Facebook.php b/extensions/yii/authclient/clients/Facebook.php index 7c17c27..4a5014d 100644 --- a/extensions/yii/authclient/clients/Facebook.php +++ b/extensions/yii/authclient/clients/Facebook.php @@ -13,6 +13,24 @@ use yii\authclient\OAuth2; * Facebook allows authentication via Facebook OAuth. * In order to use Facebook OAuth you must register your application at [[https://developers.facebook.com/apps]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'facebook' => [ + * 'class' => 'yii\authclient\clients\Facebook', + * 'clientId' => 'facebook_client_id', + * 'clientSecret' => 'facebook_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see https://developers.facebook.com/apps * @see http://developers.facebook.com/docs/reference/api * @@ -45,4 +63,20 @@ class Facebook extends OAuth2 { return $this->api('me', 'GET'); } + + /** + * @inheritdoc + */ + protected function defaultName() + { + return 'facebook'; + } + + /** + * @inheritdoc + */ + protected function defaultTitle() + { + return 'Facebook'; + } } \ No newline at end of file diff --git a/extensions/yii/authclient/clients/GitHub.php b/extensions/yii/authclient/clients/GitHub.php index 796b86e..57f430d 100644 --- a/extensions/yii/authclient/clients/GitHub.php +++ b/extensions/yii/authclient/clients/GitHub.php @@ -13,6 +13,24 @@ use yii\authclient\OAuth2; * GitHub allows authentication via GitHub OAuth. * In order to use GitHub OAuth you must register your application at [[https://github.com/settings/applications/new]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'github' => [ + * 'class' => 'yii\authclient\clients\GitHub', + * 'clientId' => 'github_client_id', + * 'clientSecret' => 'github_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see http://developer.github.com/v3/oauth/ * @see https://github.com/settings/applications/new * diff --git a/extensions/yii/authclient/clients/GoogleOAuth.php b/extensions/yii/authclient/clients/GoogleOAuth.php index 2fcd0c1..313358e 100644 --- a/extensions/yii/authclient/clients/GoogleOAuth.php +++ b/extensions/yii/authclient/clients/GoogleOAuth.php @@ -13,6 +13,24 @@ use yii\authclient\OAuth2; * GoogleOAuth allows authentication via Google OAuth. * In order to use Google OAuth you must register your application at [[https://code.google.com/apis/console#access]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'google' => [ + * 'class' => 'yii\authclient\clients\GoogleOAuth', + * 'clientId' => 'google_client_id', + * 'clientSecret' => 'google_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see https://code.google.com/apis/console#access * @see https://developers.google.com/google-apps/contacts/v3/ * diff --git a/extensions/yii/authclient/clients/GoogleOpenId.php b/extensions/yii/authclient/clients/GoogleOpenId.php index cf5a3b4..8b463d6 100644 --- a/extensions/yii/authclient/clients/GoogleOpenId.php +++ b/extensions/yii/authclient/clients/GoogleOpenId.php @@ -13,6 +13,22 @@ use yii\authclient\OpenId; * GoogleOpenId allows authentication via Google OpenId. * Unlike Google OAuth you do not need to register your application anywhere in order to use Google OpenId. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'google' => [ + * 'class' => 'yii\authclient\clients\GoogleOpenId' + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @author Paul Klimov * @since 2.0 */ diff --git a/extensions/yii/authclient/clients/LinkedIn.php b/extensions/yii/authclient/clients/LinkedIn.php index c6de848..130fda3 100644 --- a/extensions/yii/authclient/clients/LinkedIn.php +++ b/extensions/yii/authclient/clients/LinkedIn.php @@ -15,6 +15,24 @@ use Yii; * LinkedIn allows authentication via LinkedIn OAuth. * In order to use linkedIn OAuth you must register your application at [[https://www.linkedin.com/secure/developer]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'linkedin' => [ + * 'class' => 'yii\authclient\clients\LinkedIn', + * 'clientId' => 'linkedin_client_id', + * 'clientSecret' => 'linkedin_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see http://developer.linkedin.com/documents/authentication * @see https://www.linkedin.com/secure/developer * @see http://developer.linkedin.com/apis @@ -130,4 +148,20 @@ class LinkedIn extends OAuth2 protected function generateAuthState() { return sha1(uniqid(get_class($this), true)); } + + /** + * @inheritdoc + */ + protected function defaultName() + { + return 'linkedin'; + } + + /** + * @inheritdoc + */ + protected function defaultTitle() + { + return 'LinkedIn'; + } } \ No newline at end of file diff --git a/extensions/yii/authclient/clients/Twitter.php b/extensions/yii/authclient/clients/Twitter.php index 839cfce..e3c99f9 100644 --- a/extensions/yii/authclient/clients/Twitter.php +++ b/extensions/yii/authclient/clients/Twitter.php @@ -13,6 +13,24 @@ use yii\authclient\OAuth1; * Twitter allows authentication via Twitter OAuth. * In order to use Twitter OAuth you must register your application at [[https://dev.twitter.com/apps/new]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'twitter' => [ + * 'class' => 'yii\authclient\clients\Twitter', + * 'consumerKey' => 'twitter_consumer_key', + * 'consumerSecret' => 'twitter_consumer_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see https://dev.twitter.com/apps/new * @see https://dev.twitter.com/docs/api * @@ -53,4 +71,20 @@ class Twitter extends OAuth1 { return $this->api('account/verify_credentials.json', 'GET'); } + + /** + * @inheritdoc + */ + protected function defaultName() + { + return 'twitter'; + } + + /** + * @inheritdoc + */ + protected function defaultTitle() + { + return 'Twitter'; + } } \ No newline at end of file diff --git a/extensions/yii/authclient/clients/YandexOAuth.php b/extensions/yii/authclient/clients/YandexOAuth.php index 83e1072..667d019 100644 --- a/extensions/yii/authclient/clients/YandexOAuth.php +++ b/extensions/yii/authclient/clients/YandexOAuth.php @@ -13,6 +13,24 @@ use yii\authclient\OAuth2; * YandexOAuth allows authentication via Yandex OAuth. * In order to use Yandex OAuth you must register your application at [[https://oauth.yandex.ru/client/new]]. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'yandex' => [ + * 'class' => 'yii\authclient\clients\YandexOAuth', + * 'clientId' => 'yandex_client_id', + * 'clientSecret' => 'yandex_client_secret', + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @see https://oauth.yandex.ru/client/new * @see http://api.yandex.ru/login/doc/dg/reference/response.xml * diff --git a/extensions/yii/authclient/clients/YandexOpenId.php b/extensions/yii/authclient/clients/YandexOpenId.php index 9aedf2d..20c3b81 100644 --- a/extensions/yii/authclient/clients/YandexOpenId.php +++ b/extensions/yii/authclient/clients/YandexOpenId.php @@ -13,6 +13,22 @@ use yii\authclient\OpenId; * YandexOpenId allows authentication via Yandex OpenId. * Unlike Yandex OAuth you do not need to register your application anywhere in order to use Yandex OpenId. * + * Example application configuration: + * + * ~~~ + * 'components' => [ + * 'authClientCollection' => [ + * 'class' => 'yii\authclient\Collection', + * 'clients' => [ + * 'yandex' => [ + * 'class' => 'yii\authclient\clients\YandexOpenId' + * ], + * ], + * ] + * ... + * ] + * ~~~ + * * @author Paul Klimov * @since 2.0 */ diff --git a/extensions/yii/authclient/widgets/assets/authchoice.js b/extensions/yii/authclient/widgets/assets/authchoice.js index ed59e9a..3e019d9 100644 --- a/extensions/yii/authclient/widgets/assets/authchoice.js +++ b/extensions/yii/authclient/widgets/assets/authchoice.js @@ -1,3 +1,14 @@ +/** + * Yii auth choice widget. + * + * This is the JavaScript widget used by the yii\authclient\widgets\Choice widget. + * + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + * @author Paul Klimov + * @since 2.0 + */ jQuery(function($) { $.fn.authchoice = function(options) { options = $.extend({