Commits

hdknr  committed e9675ec

django-social-authについて

  • Participants
  • Parent commits 1454029

Comments (0)

Files changed (94)

File socialauth/.buildinfo

+# Sphinx build info version 1
+# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
+config: 97622b9047b6ae2634a61e3313009ed9
+tags: fbb0d17656682115ca4d033fb2f83ba1

File socialauth/_images/1.png

Added
New image

File socialauth/_images/2.png

Added
New image

File socialauth/_images/3.png

Added
New image

File socialauth/_images/4.png

Added
New image

File socialauth/_images/created.gist.png

Added
New image

File socialauth/_modules/index.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>Overview: module code &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../_static/jquery.js"></script>
+    <script type="text/javascript" src="../_static/underscore.js"></script>
+    <script type="text/javascript" src="../_static/doctools.js"></script>
+    <script type="text/javascript" src="../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>All modules for which code is available</h1>
+<ul><li><a href="social_auth/backends/contrib/github.html">social_auth.backends.contrib.github</a></li>
+<li><a href="social_auth/backends/pipeline/associate.html">social_auth.backends.pipeline.associate</a></li>
+<li><a href="social_auth/backends/pipeline/misc.html">social_auth.backends.pipeline.misc</a></li>
+<li><a href="social_auth/backends/pipeline/social.html">social_auth.backends.pipeline.social</a></li>
+<li><a href="social_auth/backends/pipeline/user.html">social_auth.backends.pipeline.user</a></li>
+<li><a href="social_auth/db/base.html">social_auth.db.base</a></li>
+<li><a href="social_auth/db/django_models.html">social_auth.db.django_models</a></li>
+<li><a href="social_auth/decorators.html">social_auth.decorators</a></li>
+</ul>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/backends/contrib/github.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.backends.contrib.github &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../../index.html" />
+    <link rel="up" title="Module code" href="../../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.backends.contrib.github</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">GitHub OAuth サポート</span>
+
+<span class="sd">This contribution adds support for GitHub OAuth service. </span>
+
+<span class="sd">- Github アプリケーション登録プロセスで アプリケーション登録が必要です</span>
+<span class="sd">- 登録したら、Djangoのsettingsでクレデンシャルを設定します</span>
+
+<span class="sd">    - settings.GITHUB_APP_ID </span>
+<span class="sd">    - settings.GITHUB_API_SECRET </span>
+
+<span class="sd">- settings.GITHUB_EXTENDED_PERMISSIONS でパーミッションを設定します。</span>
+<span class="sd">- UserSocialAuth.extra_data にはデフォルトで以下のパラメータが追加されています</span>
+<span class="sd">  (拡張するには OAuthBackend をみてください )</span>
+
+<span class="sd">    - アカウントID</span>
+<span class="sd">    - トークン有効期限</span>
+
+<span class="sd">&quot;&quot;&quot;</span>
+<span class="kn">from</span> <span class="nn">urllib</span> <span class="kn">import</span> <span class="n">urlencode</span>
+
+<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">simplejson</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.utils</span> <span class="kn">import</span> <span class="n">setting</span><span class="p">,</span> <span class="n">dsa_urlopen</span>
+<span class="kn">from</span> <span class="nn">social_auth.backends</span> <span class="kn">import</span> <span class="n">BaseOAuth2</span><span class="p">,</span> <span class="n">OAuthBackend</span><span class="p">,</span> <span class="n">USERNAME</span>
+
+
+<span class="c"># GitHub configuration</span>
+<span class="n">GITHUB_AUTHORIZATION_URL</span> <span class="o">=</span> <span class="s">&#39;https://github.com/login/oauth/authorize&#39;</span>
+<span class="n">GITHUB_ACCESS_TOKEN_URL</span> <span class="o">=</span> <span class="s">&#39;https://github.com/login/oauth/access_token&#39;</span>
+<span class="n">GITHUB_USER_DATA_URL</span> <span class="o">=</span> <span class="s">&#39;https://api.github.com/user&#39;</span>
+<span class="n">GITHUB_SERVER</span> <span class="o">=</span> <span class="s">&#39;github.com&#39;</span>
+
+
+<div class="viewcode-block" id="GithubBackend"><a class="viewcode-back" href="../../../../social_auth.conf.html#social_auth.backends.contrib.github.GithubBackend">[docs]</a><span class="k">class</span> <span class="nc">GithubBackend</span><span class="p">(</span><span class="n">OAuthBackend</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Github OAuth authentication backend&quot;&quot;&quot;</span>
+    <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;github&#39;</span>
+    <span class="sd">&#39;&#39;&#39; バックエンド名称 &#39;&#39;&#39;</span>
+    <span class="n">EXTRA_DATA</span> <span class="o">=</span> <span class="p">[</span>
+        <span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="s">&#39;id&#39;</span><span class="p">),</span>
+        <span class="p">(</span><span class="s">&#39;expires&#39;</span><span class="p">,</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_EXPIRATION&#39;</span><span class="p">,</span> <span class="s">&#39;expires&#39;</span><span class="p">))</span>
+    <span class="p">]</span>
+    <span class="sd">&#39;&#39;&#39; 拡張データ &#39;&#39;&#39;</span>
+
+<div class="viewcode-block" id="GithubBackend.get_user_details"><a class="viewcode-back" href="../../../../social_auth.conf.html#social_auth.backends.contrib.github.GithubBackend.get_user_details">[docs]</a>    <span class="k">def</span> <span class="nf">get_user_details</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return user details from Github account&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="p">{</span><span class="n">USERNAME</span><span class="p">:</span> <span class="n">response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;login&#39;</span><span class="p">),</span>
+                <span class="s">&#39;email&#39;</span><span class="p">:</span> <span class="n">response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;email&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="s">&#39;&#39;</span><span class="p">,</span>
+                <span class="s">&#39;first_name&#39;</span><span class="p">:</span> <span class="n">response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">)}</span>
+</div></div>
+<div class="viewcode-block" id="GithubAuth"><a class="viewcode-back" href="../../../../social_auth.conf.html#social_auth.backends.contrib.github.GithubAuth">[docs]</a><span class="k">class</span> <span class="nc">GithubAuth</span><span class="p">(</span><span class="n">BaseOAuth2</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Github OAuth2 mechanism&quot;&quot;&quot;</span>
+    <span class="n">AUTHORIZATION_URL</span> <span class="o">=</span> <span class="n">GITHUB_AUTHORIZATION_URL</span>
+    <span class="sd">&#39;&#39;&#39; OAuth オーソライゼーションエンドポイント &#39;&#39;&#39;</span>
+    <span class="n">ACCESS_TOKEN_URL</span> <span class="o">=</span> <span class="n">GITHUB_ACCESS_TOKEN_URL</span>
+    <span class="sd">&#39;&#39;&#39; OAuth トークンエンドポイント &#39;&#39;&#39;</span>
+    <span class="n">AUTH_BACKEND</span> <span class="o">=</span> <span class="n">GithubBackend</span>
+    <span class="sd">&#39;&#39;&#39; 認証バックエンドクラス&#39;&#39;&#39;</span>
+    <span class="n">SETTINGS_KEY_NAME</span> <span class="o">=</span> <span class="s">&#39;GITHUB_APP_ID&#39;</span>
+    <span class="sd">&#39;&#39;&#39; OAuth client_id の設定名&#39;&#39;&#39;</span>
+    <span class="n">SETTINGS_SECRET_NAME</span> <span class="o">=</span> <span class="s">&#39;GITHUB_API_SECRET&#39;</span>
+    <span class="sd">&#39;&#39;&#39; OAuth client_secretの設定名 &#39;&#39;&#39;</span>
+    <span class="n">SCOPE_SEPARATOR</span> <span class="o">=</span> <span class="s">&#39;,&#39;</span>
+    <span class="sd">&#39;&#39;&#39; スコープ区切り文字 &#39;&#39;&#39;</span>
+    <span class="n">SCOPE_VAR_NAME</span> <span class="o">=</span> <span class="s">&#39;GITHUB_EXTENDED_PERMISSIONS&#39;</span>
+    <span class="sd">&#39;&#39;&#39;スコープ Versio 名 ( http://developer.github.com/v3/oauth/ ) &#39;&#39;&#39;</span>
+
+<div class="viewcode-block" id="GithubAuth.user_data"><a class="viewcode-back" href="../../../../social_auth.conf.html#social_auth.backends.contrib.github.GithubAuth.user_data">[docs]</a>    <span class="k">def</span> <span class="nf">user_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">access_token</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Loads user data from service&quot;&quot;&quot;</span>
+        <span class="n">url</span> <span class="o">=</span> <span class="n">GITHUB_USER_DATA_URL</span> <span class="o">+</span> <span class="s">&#39;?&#39;</span> <span class="o">+</span> <span class="n">urlencode</span><span class="p">({</span>
+            <span class="s">&#39;access_token&#39;</span><span class="p">:</span> <span class="n">access_token</span>
+        <span class="p">})</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">simplejson</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">dsa_urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">))</span>
+        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">None</span>
+
+<span class="c"># Backend definition</span></div></div>
+<span class="n">BACKENDS</span> <span class="o">=</span> <span class="p">{</span>
+    <span class="s">&#39;github&#39;</span><span class="p">:</span> <span class="n">GithubAuth</span><span class="p">,</span>
+<span class="p">}</span>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/backends/pipeline/associate.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.backends.pipeline.associate &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../../index.html" />
+    <link rel="up" title="Module code" href="../../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.backends.pipeline.associate</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+
+<span class="kn">from</span> <span class="nn">django.core.exceptions</span> <span class="kn">import</span> <span class="n">MultipleObjectsReturned</span><span class="p">,</span> <span class="n">ObjectDoesNotExist</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">UserSocialAuth</span>
+<span class="kn">from</span> <span class="nn">social_auth.exceptions</span> <span class="kn">import</span> <span class="n">AuthException</span>
+
+
+<div class="viewcode-block" id="associate_by_email"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.associate.associate_by_email">[docs]</a><span class="k">def</span> <span class="nf">associate_by_email</span><span class="p">(</span><span class="n">details</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot; 指定されたメールアドレスに対応するソーシャルユーザーを渡す</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="n">user</span><span class="p">:</span>
+        <span class="k">return</span> <span class="bp">None</span>
+
+    <span class="n">email</span> <span class="o">=</span> <span class="n">details</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;email&#39;</span><span class="p">)</span>
+
+    <span class="k">if</span> <span class="n">email</span><span class="p">:</span>
+        <span class="c"># try to associate accounts registered with the same email address,</span>
+        <span class="c"># only if it&#39;s a single object. AuthException is raised if multiple</span>
+        <span class="c"># objects are returned</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="k">return</span> <span class="p">{</span><span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">get_user_by_email</span><span class="p">(</span><span class="n">email</span><span class="o">=</span><span class="n">email</span><span class="p">)}</span>
+        <span class="k">except</span> <span class="n">MultipleObjectsReturned</span><span class="p">:</span>
+            <span class="k">raise</span> <span class="n">AuthException</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;backend&#39;</span><span class="p">],</span> <span class="s">&#39;Not unique email address.&#39;</span><span class="p">)</span>
+        <span class="k">except</span> <span class="n">ObjectDoesNotExist</span><span class="p">:</span>
+            <span class="k">pass</span></div>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/backends/pipeline/misc.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.backends.pipeline.misc &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../../index.html" />
+    <link rel="up" title="Module code" href="../../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.backends.pipeline.misc</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="kn">from</span> <span class="nn">social_auth.backends</span> <span class="kn">import</span> <span class="n">PIPELINE</span>
+<span class="kn">from</span> <span class="nn">social_auth.utils</span> <span class="kn">import</span> <span class="n">setting</span>
+
+
+<div class="viewcode-block" id="save_status_to_session"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.misc.save_status_to_session">[docs]</a><span class="k">def</span> <span class="nf">save_status_to_session</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">auth</span><span class="p">,</span> <span class="n">pipeline_index</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;  現在の social-auth 状態をセッションに保持します </span>
+
+<span class="sd">        :param auth: social_auth.backends.BaseAuth の派生クラス (Twtter,Facebook,Github...)</span>
+<span class="sd">        :param pipeline_index: settings.SOCIAL_AUTH_PIPELINE パイプラインの何番目にあるか</span>
+<span class="sd">        :param args: パラメータ </span>
+<span class="sd">        :param kwargs: パラメータ </span>
+
+<span class="sd">        - auth.to_session_dict(次のパイプラインインデックス、args,kwargs)でシリアライズ</span>
+<span class="sd">        - シリアライズしたデータを settings.SOCIAL_AUTH_PARTIAL_PIPELINE_KEY のキーでセッションに保持</span>
+<span class="sd">        - もしも、settings.SOCIAL_AUTH_PIPELINE_RESUME_ENTRY  が定義されていると、</span>
+<span class="sd">          パイプラインは強制的にこのエントリから始まります。</span>
+
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">next_entry</span> <span class="o">=</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_PIPELINE_RESUME_ENTRY&#39;</span><span class="p">)</span>
+
+    <span class="k">if</span> <span class="n">next_entry</span> <span class="ow">and</span> <span class="n">next_entry</span> <span class="ow">in</span> <span class="n">PIPELINE</span><span class="p">:</span>
+        <span class="n">idx</span> <span class="o">=</span> <span class="n">PIPELINE</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">next_entry</span><span class="p">)</span>
+    <span class="k">else</span><span class="p">:</span>
+        <span class="n">idx</span> <span class="o">=</span> <span class="n">pipeline_index</span> <span class="o">+</span> <span class="mi">1</span>
+
+    <span class="n">data</span> <span class="o">=</span> <span class="n">auth</span><span class="o">.</span><span class="n">to_session_dict</span><span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+    <span class="n">name</span> <span class="o">=</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_PARTIAL_PIPELINE_KEY&#39;</span><span class="p">,</span> <span class="s">&#39;partial_pipeline&#39;</span><span class="p">)</span>
+    <span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span></div>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/backends/pipeline/social.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.backends.pipeline.social &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../../index.html" />
+    <link rel="up" title="Module code" href="../../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.backends.pipeline.social</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">ugettext</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">UserSocialAuth</span><span class="p">,</span> <span class="n">SOCIAL_AUTH_MODELS_MODULE</span>
+<span class="kn">from</span> <span class="nn">social_auth.exceptions</span> <span class="kn">import</span> <span class="n">AuthAlreadyAssociated</span>
+
+
+<div class="viewcode-block" id="social_auth_user"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.social.social_auth_user">[docs]</a><span class="k">def</span> <span class="nf">social_auth_user</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Return UserSocialAuth account for backend/uid pair or None if it</span>
+<span class="sd">    doesn&#39;t exists.</span>
+
+<span class="sd">    Raise AuthAlreadyAssociated if UserSocialAuth entry belongs to another</span>
+<span class="sd">    user.</span>
+
+
+<span class="sd">    :rtype: social_user, user のdict</span>
+
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">social_user</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">get_social_auth</span><span class="p">(</span><span class="n">backend</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">uid</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">social_user</span><span class="p">:</span>
+        <span class="k">if</span> <span class="n">user</span> <span class="ow">and</span> <span class="n">social_user</span><span class="o">.</span><span class="n">user</span> <span class="o">!=</span> <span class="n">user</span><span class="p">:</span>
+            <span class="n">msg</span> <span class="o">=</span> <span class="n">ugettext</span><span class="p">(</span><span class="s">&#39;This </span><span class="si">%(provider)s</span><span class="s"> account is already in use.&#39;</span><span class="p">)</span>
+            <span class="k">raise</span> <span class="n">AuthAlreadyAssociated</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">msg</span> <span class="o">%</span> <span class="p">{</span>
+                <span class="s">&#39;provider&#39;</span><span class="p">:</span> <span class="n">backend</span><span class="o">.</span><span class="n">name</span>
+            <span class="p">})</span>
+        <span class="k">elif</span> <span class="ow">not</span> <span class="n">user</span><span class="p">:</span>
+            <span class="n">user</span> <span class="o">=</span> <span class="n">social_user</span><span class="o">.</span><span class="n">user</span>
+    <span class="k">return</span> <span class="p">{</span><span class="s">&#39;social_user&#39;</span><span class="p">:</span> <span class="n">social_user</span><span class="p">,</span> <span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">user</span><span class="p">}</span>
+
+</div>
+<div class="viewcode-block" id="associate_user"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.social.associate_user">[docs]</a><span class="k">def</span> <span class="nf">associate_user</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">social_user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Associate user social account with user instance.&quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="n">social_user</span><span class="p">:</span>
+        <span class="k">return</span> <span class="bp">None</span>
+
+    <span class="k">if</span> <span class="ow">not</span> <span class="n">user</span><span class="p">:</span>
+        <span class="k">return</span> <span class="p">{}</span>
+
+    <span class="k">try</span><span class="p">:</span>
+        <span class="n">social</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">create_social_auth</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">backend</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
+    <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">SOCIAL_AUTH_MODELS_MODULE</span><span class="o">.</span><span class="n">is_integrity_error</span><span class="p">(</span><span class="n">e</span><span class="p">):</span>
+            <span class="k">raise</span>
+        <span class="c"># Protect for possible race condition, those bastard with FTL</span>
+        <span class="c"># clicking capabilities, check issue #131:</span>
+        <span class="c">#   https://github.com/omab/django-social-auth/issues/131</span>
+        <span class="k">return</span> <span class="n">social_auth_user</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">social_user</span><span class="o">=</span><span class="n">social_user</span><span class="p">,</span>
+                                <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+    <span class="k">else</span><span class="p">:</span>
+        <span class="k">return</span> <span class="p">{</span><span class="s">&#39;social_user&#39;</span><span class="p">:</span> <span class="n">social</span><span class="p">,</span> <span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">social</span><span class="o">.</span><span class="n">user</span><span class="p">}</span>
+
+</div>
+<div class="viewcode-block" id="load_extra_data"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.social.load_extra_data">[docs]</a><span class="k">def</span> <span class="nf">load_extra_data</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">details</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">social_user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+                    <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Load extra data from provider and store it on current UserSocialAuth</span>
+<span class="sd">    extra_data field.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">social_user</span> <span class="o">=</span> <span class="n">social_user</span> <span class="ow">or</span> \
+                  <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">get_social_auth</span><span class="p">(</span><span class="n">backend</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">uid</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">social_user</span><span class="p">:</span>
+        <span class="n">extra_data</span> <span class="o">=</span> <span class="n">backend</span><span class="o">.</span><span class="n">extra_data</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">details</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">extra_data</span> <span class="ow">and</span> <span class="n">social_user</span><span class="o">.</span><span class="n">extra_data</span> <span class="o">!=</span> <span class="n">extra_data</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">social_user</span><span class="o">.</span><span class="n">extra_data</span><span class="p">:</span>
+                <span class="n">social_user</span><span class="o">.</span><span class="n">extra_data</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">extra_data</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">social_user</span><span class="o">.</span><span class="n">extra_data</span> <span class="o">=</span> <span class="n">extra_data</span>
+            <span class="n">social_user</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
+        <span class="k">return</span> <span class="p">{</span><span class="s">&#39;social_user&#39;</span><span class="p">:</span> <span class="n">social_user</span><span class="p">}</span></div>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/backends/pipeline/user.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.backends.pipeline.user &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../../index.html" />
+    <link rel="up" title="Module code" href="../../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.backends.pipeline.user</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+
+<span class="kn">from</span> <span class="nn">uuid</span> <span class="kn">import</span> <span class="n">uuid4</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.utils</span> <span class="kn">import</span> <span class="n">setting</span>
+<span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">UserSocialAuth</span>
+<span class="kn">from</span> <span class="nn">social_auth.backends</span> <span class="kn">import</span> <span class="n">USERNAME</span>
+<span class="kn">from</span> <span class="nn">social_auth.signals</span> <span class="kn">import</span> <span class="n">socialauth_registered</span><span class="p">,</span> \
+                                <span class="n">pre_update</span>
+
+
+<div class="viewcode-block" id="get_username"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.user.get_username">[docs]</a><span class="k">def</span> <span class="nf">get_username</span><span class="p">(</span><span class="n">details</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
+                 <span class="n">user_exists</span><span class="o">=</span><span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">simple_user_exists</span><span class="p">,</span>
+                 <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot; 新規ユーザーの username を次のパイプラインに渡す</span>
+
+<span class="sd">        - userが指定されていれば、その username を返す</span>
+
+<span class="sd">        :param details: ユーザー属性データ(dict)</span>
+<span class="sd">        :param user: システムユーザー </span>
+<span class="sd">        :param user_exists: ユーザーが存在するかを確認するcallable</span>
+<span class="sd">        :param args: list 引数</span>
+<span class="sd">        :param kwargs: dict 引数</span>
+<span class="sd">        :return: {&#39;usernmae&#39;: &#39;ユーザー名 &#39;} </span>
+<span class="sd">    </span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="n">user</span><span class="p">:</span>
+        <span class="k">return</span> <span class="p">{</span><span class="s">&#39;username&#39;</span><span class="p">:</span> <span class="n">user</span><span class="o">.</span><span class="n">username</span><span class="p">}</span>
+
+    <span class="k">if</span> <span class="n">details</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">USERNAME</span><span class="p">):</span>
+        <span class="n">username</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">details</span><span class="p">[</span><span class="n">USERNAME</span><span class="p">])</span>
+    <span class="k">else</span><span class="p">:</span>
+        <span class="n">username</span> <span class="o">=</span> <span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">get_hex</span><span class="p">()</span>
+
+    <span class="n">uuid_length</span> <span class="o">=</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_UUID_LENGTH&#39;</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>
+    <span class="n">max_length</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">username_max_length</span><span class="p">()</span>
+    <span class="n">short_username</span> <span class="o">=</span> <span class="n">username</span><span class="p">[:</span><span class="n">max_length</span> <span class="o">-</span> <span class="n">uuid_length</span><span class="p">]</span>
+    <span class="n">final_username</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">clean_username</span><span class="p">(</span><span class="n">username</span><span class="p">[:</span><span class="n">max_length</span><span class="p">])</span>
+
+    <span class="c"># Generate a unique username for current user using username</span>
+    <span class="c"># as base but adding a unique hash at the end. Original</span>
+    <span class="c"># username is cut to avoid any field max_length.</span>
+    <span class="k">while</span> <span class="n">user_exists</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="n">final_username</span><span class="p">):</span>
+        <span class="n">username</span> <span class="o">=</span> <span class="n">short_username</span> <span class="o">+</span> <span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">get_hex</span><span class="p">()[:</span><span class="n">uuid_length</span><span class="p">]</span>
+        <span class="n">final_username</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">clean_username</span><span class="p">(</span><span class="n">username</span><span class="p">[:</span><span class="n">max_length</span><span class="p">])</span>
+
+    <span class="k">return</span> <span class="p">{</span><span class="s">&#39;username&#39;</span><span class="p">:</span> <span class="n">final_username</span><span class="p">}</span>
+
+</div>
+<div class="viewcode-block" id="create_user"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.user.create_user">[docs]</a><span class="k">def</span> <span class="nf">create_user</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">details</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+                <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot; ソーシャルユーザーを作成して、次のパイプラインに渡す </span>
+
+<span class="sd">        - userが指定されていると、それをフォワードする(既存ユーザー)</span>
+
+<span class="sd">        :param backend: バックエンド</span>
+<span class="sd">        :param details: ユーザー属性</span>
+<span class="sd">        :param response: 応答</span>
+<span class="sd">        :param uid: User ID</span>
+<span class="sd">        :param username: username</span>
+<span class="sd">        :param user: ソーシャルユーザー</span>
+<span class="sd">        :param args: list 引数</span>
+<span class="sd">        :param kwargs: dict 引数</span>
+<span class="sd">        :return: {&#39;user&#39;: &#39;ソーシャルユーザー&#39;, &#39;is_new&#39; : True }</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="n">user</span><span class="p">:</span>
+        <span class="k">return</span> <span class="p">{</span><span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">user</span><span class="p">}</span>
+    <span class="k">if</span> <span class="ow">not</span> <span class="n">username</span><span class="p">:</span>
+        <span class="k">return</span> <span class="bp">None</span>
+
+    <span class="k">return</span> <span class="p">{</span>
+        <span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">create_user</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="n">username</span><span class="p">,</span>
+                                           <span class="n">email</span><span class="o">=</span><span class="n">details</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;email&#39;</span><span class="p">)),</span>
+        <span class="s">&#39;is_new&#39;</span><span class="p">:</span> <span class="bp">True</span>
+    <span class="p">}</span>
+
+</div>
+<div class="viewcode-block" id="update_user_details"><a class="viewcode-back" href="../../../../backends.pipeline.html#social_auth.backends.pipeline.user.update_user_details">[docs]</a><span class="k">def</span> <span class="nf">update_user_details</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">details</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">is_new</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
+                        <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;  ユーザー属性を更新する</span>
+
+<span class="sd">        - 更新まえにシグナル(pre_update)を出して、アプリケーションがデータを処理出来るようにする</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">if</span> <span class="n">user</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+        <span class="k">return</span>
+
+    <span class="n">changed</span> <span class="o">=</span> <span class="bp">False</span>  <span class="c"># flag to track changes</span>
+
+    <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">details</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+        <span class="c"># do not update username, it was already generated</span>
+        <span class="c"># do not update configured fields if user already existed</span>
+        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">(</span><span class="n">USERNAME</span><span class="p">,</span> <span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="s">&#39;pk&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="ow">not</span> <span class="n">is_new</span> <span class="ow">and</span>
+            <span class="n">name</span> <span class="ow">in</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_PROTECTED_USER_FIELDS&#39;</span><span class="p">,</span> <span class="p">[])):</span>
+            <span class="k">continue</span>
+        <span class="k">if</span> <span class="n">value</span> <span class="ow">and</span> <span class="n">value</span> <span class="o">!=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
+            <span class="nb">setattr</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+            <span class="n">changed</span> <span class="o">=</span> <span class="bp">True</span>
+
+    <span class="c"># Fire a pre-update signal sending current backend instance,</span>
+    <span class="c"># user instance (created or retrieved from database), service</span>
+    <span class="c"># response and processed details.</span>
+    <span class="c">#</span>
+    <span class="c"># Also fire socialauth_registered signal for newly registered</span>
+    <span class="c"># users.</span>
+    <span class="c">#</span>
+    <span class="c"># Signal handlers must return True or False to signal instance</span>
+    <span class="c"># changes. Send method returns a list of tuples with receiver</span>
+    <span class="c"># and it&#39;s response.</span>
+    <span class="n">signal_response</span> <span class="o">=</span> <span class="k">lambda</span> <span class="p">(</span><span class="n">receiver</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span> <span class="n">response</span>
+    <span class="n">signal_kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;sender&#39;</span><span class="p">:</span> <span class="n">backend</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="s">&#39;user&#39;</span><span class="p">:</span> <span class="n">user</span><span class="p">,</span>
+                     <span class="s">&#39;response&#39;</span><span class="p">:</span> <span class="n">response</span><span class="p">,</span> <span class="s">&#39;details&#39;</span><span class="p">:</span> <span class="n">details</span><span class="p">}</span>
+
+    <span class="n">changed</span> <span class="o">|=</span> <span class="nb">any</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span> <span class="n">pre_update</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="o">**</span><span class="n">signal_kwargs</span><span class="p">)))</span>
+
+    <span class="c"># Fire socialauth_registered signal on new user registration</span>
+    <span class="k">if</span> <span class="n">is_new</span><span class="p">:</span>
+        <span class="n">changed</span> <span class="o">|=</span> <span class="nb">any</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
+                              <span class="n">socialauth_registered</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="o">**</span><span class="n">signal_kwargs</span><span class="p">)))</span>
+
+    <span class="k">if</span> <span class="n">changed</span><span class="p">:</span>
+        <span class="n">user</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></div>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/db/base.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.db.base &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../index.html" />
+    <link rel="up" title="Module code" href="../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.db.base</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="sd">&quot;&quot;&quot;Models mixins for Social Auth&quot;&quot;&quot;</span>
+<span class="kn">import</span> <span class="nn">base64</span>
+<span class="kn">import</span> <span class="nn">time</span>
+<span class="kn">import</span> <span class="nn">re</span>
+<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
+
+<span class="kn">from</span> <span class="nn">openid.association</span> <span class="kn">import</span> <span class="n">Association</span> <span class="k">as</span> <span class="n">OIDAssociation</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.utils</span> <span class="kn">import</span> <span class="n">setting</span><span class="p">,</span> <span class="n">utc</span>
+
+<span class="c"># django.contrib.auth and mongoengine.django.auth regex to validate usernames</span>
+<span class="c"># &#39;^[\w@.+-_]+$&#39;, we use the opposite to clean invalid characters</span>
+<span class="n">CLEAN_USERNAME_REGEX</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">r&#39;[^\w.@+-_]+&#39;</span><span class="p">)</span>
+
+
+<div class="viewcode-block" id="UserSocialAuthMixin"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin">[docs]</a><span class="k">class</span> <span class="nc">UserSocialAuthMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="n">user</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="sd">&#39;&#39;&#39; ユーザー &#39;&#39;&#39;</span>
+    <span class="n">provider</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="sd">&#39;&#39;&#39; プロバイダー &#39;&#39;&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return associated user unicode representation&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">provider</span><span class="o">.</span><span class="n">title</span><span class="p">())</span>
+
+    <span class="nd">@property</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.tokens"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.tokens">[docs]</a>    <span class="k">def</span> <span class="nf">tokens</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return access_token stored in extra_data or None&quot;&quot;&quot;</span>
+        <span class="c"># Make import here to avoid recursive imports :-/</span>
+        <span class="kn">from</span> <span class="nn">social_auth.backends</span> <span class="kn">import</span> <span class="n">get_backends</span>
+        <span class="n">backend</span> <span class="o">=</span> <span class="n">get_backends</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">provider</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">backend</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">backend</span><span class="o">.</span><span class="n">AUTH_BACKEND</span><span class="o">.</span><span class="n">tokens</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">return</span> <span class="p">{}</span>
+</div>
+<div class="viewcode-block" id="UserSocialAuthMixin.expiration_datetime"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.expiration_datetime">[docs]</a>    <span class="k">def</span> <span class="nf">expiration_datetime</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Return provider session live seconds. Returns a timedelta ready to</span>
+<span class="sd">        use with session.set_expiry().</span>
+
+<span class="sd">        If provider returns a timestamp instead of session seconds to live, the</span>
+<span class="sd">        timedelta is inferred from current time (using UTC timezone). None is</span>
+<span class="sd">        returned if there&#39;s no value stored or it&#39;s invalid.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">name</span> <span class="o">=</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_EXPIRATION&#39;</span><span class="p">,</span> <span class="s">&#39;expires&#39;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">extra_data</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">extra_data</span><span class="p">:</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">expires</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">extra_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
+            <span class="k">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">TypeError</span><span class="p">):</span>
+                <span class="k">return</span> <span class="bp">None</span>
+
+            <span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
+            <span class="n">now_timestamp</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">mktime</span><span class="p">(</span><span class="n">now</span><span class="o">.</span><span class="n">timetuple</span><span class="p">())</span>
+
+            <span class="c"># Detect if expires is a timestamp</span>
+            <span class="k">if</span> <span class="n">expires</span> <span class="o">&gt;</span> <span class="n">now_timestamp</span><span class="p">:</span>  <span class="c"># expires is a datetime</span>
+                <span class="k">return</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcfromtimestamp</span><span class="p">(</span><span class="n">expires</span><span class="p">)</span> \
+                               <span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">utc</span><span class="p">)</span> <span class="o">-</span> \
+                       <span class="n">now</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">tzinfo</span><span class="o">=</span><span class="n">utc</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>  <span class="c"># expires is a timedelta</span>
+                <span class="k">return</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="n">expires</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">user_model</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">&#39;Implement in subclass&#39;</span><span class="p">)</span>
+
+    <span class="nd">@classmethod</span>
+    <span class="k">def</span> <span class="nf">username_max_length</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
+        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">&#39;Implement in subclass&#39;</span><span class="p">)</span>
+
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.clean_username"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.clean_username">[docs]</a>    <span class="k">def</span> <span class="nf">clean_username</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; クリーンなユーザー名を返す &#39;&#39;&#39;</span>
+        <span class="k">return</span> <span class="n">CLEAN_USERNAME_REGEX</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.allowed_to_disconnect"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.allowed_to_disconnect">[docs]</a>    <span class="k">def</span> <span class="nf">allowed_to_disconnect</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">backend_name</span><span class="p">,</span> <span class="n">association_id</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ディスコネクトが許されているかの判定  &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="n">association_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">qs</span> <span class="o">=</span> <span class="n">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">association_id</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">qs</span> <span class="o">=</span> <span class="n">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">exclude</span><span class="p">(</span><span class="n">provider</span><span class="o">=</span><span class="n">backend_name</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s">&#39;has_usable_password&#39;</span><span class="p">):</span>
+            <span class="n">valid_password</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">has_usable_password</span><span class="p">()</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">valid_password</span> <span class="o">=</span> <span class="bp">True</span>
+
+        <span class="k">return</span> <span class="n">valid_password</span> <span class="ow">or</span> <span class="n">qs</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.simple_user_exists"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.simple_user_exists">[docs]</a>    <span class="k">def</span> <span class="nf">simple_user_exists</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return True/False if a User instance exists with the given arguments.</span>
+<span class="sd">        Arguments are directly passed to filter() manager method.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.create_user"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.create_user">[docs]</a>    <span class="k">def</span> <span class="nf">create_user</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ユーザーの新規作成 &#39;&#39;&#39;</span>
+        <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create_user</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="n">username</span><span class="p">,</span>
+                                                    <span class="n">email</span><span class="o">=</span><span class="n">email</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.get_user"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.get_user">[docs]</a>    <span class="k">def</span> <span class="nf">get_user</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">pk</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ユーザーの取得 &#39;&#39;&#39;</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">pk</span><span class="p">)</span>
+        <span class="k">except</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">None</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.get_user_by_email"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.get_user_by_email">[docs]</a>    <span class="k">def</span> <span class="nf">get_user_by_email</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">email</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; 指定したメアドのユーザーを返す &#39;&#39;&#39;</span>
+        <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">email</span><span class="o">=</span><span class="n">email</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.resolve_user_or_id"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.resolve_user_or_id">[docs]</a>    <span class="k">def</span> <span class="nf">resolve_user_or_id</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">user_or_id</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; userオブジェクトあるいはidのユーザーを返す &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">user_or_id</span><span class="p">,</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()):</span>
+            <span class="k">return</span> <span class="n">user_or_id</span>
+        <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">user_or_id</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.get_social_auth"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.get_social_auth">[docs]</a>    <span class="k">def</span> <span class="nf">get_social_auth</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">provider</span><span class="p">,</span> <span class="n">uid</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; provider + uid の一意なユーザーを返す &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
+            <span class="n">uid</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">uid</span><span class="p">)</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">provider</span><span class="o">=</span><span class="n">provider</span><span class="p">,</span> <span class="n">uid</span><span class="o">=</span><span class="n">uid</span><span class="p">)</span>
+        <span class="k">except</span> <span class="n">cls</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">None</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.get_social_auth_for_user"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.get_social_auth_for_user">[docs]</a>    <span class="k">def</span> <span class="nf">get_social_auth_for_user</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ユーザーの保有しているソーシャルアカウントを全て返す &#39;&#39;&#39;</span>
+        <span class="k">return</span> <span class="n">user</span><span class="o">.</span><span class="n">social_auth</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.create_social_auth"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.create_social_auth">[docs]</a>    <span class="k">def</span> <span class="nf">create_social_auth</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">provider</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ソーシャルアカウントをUserに対して追加する &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">uid</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
+            <span class="n">uid</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">uid</span><span class="p">)</span>
+        <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">,</span> <span class="n">uid</span><span class="o">=</span><span class="n">uid</span><span class="p">,</span> <span class="n">provider</span><span class="o">=</span><span class="n">provider</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.store_association"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.store_association">[docs]</a>    <span class="k">def</span> <span class="nf">store_association</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">server_url</span><span class="p">,</span> <span class="n">association</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; アソシエーションを保存する(OpenID) &#39;&#39;&#39;</span>
+        <span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">Association</span>
+        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;server_url&#39;</span><span class="p">:</span> <span class="n">server_url</span><span class="p">,</span> <span class="s">&#39;handle&#39;</span><span class="p">:</span> <span class="n">association</span><span class="o">.</span><span class="n">handle</span><span class="p">}</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="n">assoc</span> <span class="o">=</span> <span class="n">Association</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">**</span><span class="n">args</span><span class="p">)</span>
+        <span class="k">except</span> <span class="n">Association</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
+            <span class="n">assoc</span> <span class="o">=</span> <span class="n">Association</span><span class="p">(</span><span class="o">**</span><span class="n">args</span><span class="p">)</span>
+        <span class="n">assoc</span><span class="o">.</span><span class="n">secret</span> <span class="o">=</span> <span class="n">base64</span><span class="o">.</span><span class="n">encodestring</span><span class="p">(</span><span class="n">association</span><span class="o">.</span><span class="n">secret</span><span class="p">)</span>
+        <span class="n">assoc</span><span class="o">.</span><span class="n">issued</span> <span class="o">=</span> <span class="n">association</span><span class="o">.</span><span class="n">issued</span>
+        <span class="n">assoc</span><span class="o">.</span><span class="n">lifetime</span> <span class="o">=</span> <span class="n">association</span><span class="o">.</span><span class="n">lifetime</span>
+        <span class="n">assoc</span><span class="o">.</span><span class="n">assoc_type</span> <span class="o">=</span> <span class="n">association</span><span class="o">.</span><span class="n">assoc_type</span>
+        <span class="n">assoc</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.get_oid_associations"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.get_oid_associations">[docs]</a>    <span class="k">def</span> <span class="nf">get_oid_associations</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">server_url</span><span class="p">,</span> <span class="n">handle</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; アソシエーションを取得(OpenID) &#39;&#39;&#39;</span>
+        <span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">Association</span>
+        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;server_url&#39;</span><span class="p">:</span> <span class="n">server_url</span><span class="p">}</span>
+        <span class="k">if</span> <span class="n">handle</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">args</span><span class="p">[</span><span class="s">&#39;handle&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">handle</span>
+
+        <span class="k">return</span> <span class="nb">sorted</span><span class="p">([</span>
+                <span class="p">(</span><span class="n">assoc</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
+                 <span class="n">OIDAssociation</span><span class="p">(</span><span class="n">assoc</span><span class="o">.</span><span class="n">handle</span><span class="p">,</span>
+                                <span class="n">base64</span><span class="o">.</span><span class="n">decodestring</span><span class="p">(</span><span class="n">assoc</span><span class="o">.</span><span class="n">secret</span><span class="p">),</span>
+                                <span class="n">assoc</span><span class="o">.</span><span class="n">issued</span><span class="p">,</span>
+                                <span class="n">assoc</span><span class="o">.</span><span class="n">lifetime</span><span class="p">,</span>
+                                <span class="n">assoc</span><span class="o">.</span><span class="n">assoc_type</span><span class="p">))</span>
+                <span class="k">for</span> <span class="n">assoc</span> <span class="ow">in</span> <span class="n">Association</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">**</span><span class="n">args</span><span class="p">)</span>
+        <span class="p">],</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">issued</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.delete_associations"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.delete_associations">[docs]</a>    <span class="k">def</span> <span class="nf">delete_associations</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">ids_to_delete</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; アソシエーションを削除(OpenID) &#39;&#39;&#39;</span>
+        <span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">Association</span>
+        <span class="n">Association</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">pk__in</span><span class="o">=</span><span class="n">ids_to_delete</span><span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuthMixin.use_nonce"><a class="viewcode-back" href="../../../models.html#social_auth.db.base.UserSocialAuthMixin.use_nonce">[docs]</a>    <span class="k">def</span> <span class="nf">use_nonce</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">server_url</span><span class="p">,</span> <span class="n">timestamp</span><span class="p">,</span> <span class="n">salt</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; ノンスを作る/返す  (OpenID) &#39;&#39;&#39;</span>
+        <span class="kn">from</span> <span class="nn">social_auth.models</span> <span class="kn">import</span> <span class="n">Nonce</span>
+        <span class="k">return</span> <span class="n">Nonce</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get_or_create</span><span class="p">(</span><span class="n">server_url</span><span class="o">=</span><span class="n">server_url</span><span class="p">,</span>
+                                           <span class="n">timestamp</span><span class="o">=</span><span class="n">timestamp</span><span class="p">,</span>
+                                           <span class="n">salt</span><span class="o">=</span><span class="n">salt</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
+
+</div></div>
+<span class="k">class</span> <span class="nc">NonceMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;One use numbers&quot;&quot;&quot;</span>
+    <span class="n">server_url</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="n">timestamp</span> <span class="o">=</span> <span class="mi">0</span>
+    <span class="n">salt</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Unicode representation&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">server_url</span>
+
+
+<span class="k">class</span> <span class="nc">AssociationMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;OpenId account association&quot;&quot;&quot;</span>
+    <span class="n">server_url</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="n">handle</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="n">secret</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+    <span class="n">issued</span> <span class="o">=</span> <span class="mi">0</span>
+    <span class="n">lifetime</span> <span class="o">=</span> <span class="mi">0</span>
+    <span class="n">assoc_type</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+
+    <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;Unicode representation&quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">handle</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">issued</span><span class="p">)</span>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/db/django_models.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.db.django_models &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../../index.html" />
+    <link rel="up" title="Module code" href="../../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.db.django_models</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="sd">&quot;&quot;&quot;Django ORM models for Social Auth&quot;&quot;&quot;</span>
+<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
+<span class="kn">from</span> <span class="nn">django.db.utils</span> <span class="kn">import</span> <span class="n">IntegrityError</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.db.base</span> <span class="kn">import</span> <span class="n">UserSocialAuthMixin</span><span class="p">,</span> <span class="n">AssociationMixin</span><span class="p">,</span> \
+                                <span class="n">NonceMixin</span>
+<span class="kn">from</span> <span class="nn">social_auth.fields</span> <span class="kn">import</span> <span class="n">JSONField</span>
+<span class="kn">from</span> <span class="nn">social_auth.utils</span> <span class="kn">import</span> <span class="n">setting</span>
+
+
+<span class="c"># If User class is overridden, it *must* provide the following fields</span>
+<span class="c"># and methods work with django-social-auth:</span>
+<span class="c">#</span>
+<span class="c">#   username   = CharField()</span>
+<span class="c">#   last_login = DateTimeField()</span>
+<span class="c">#   is_active  = BooleanField()</span>
+<span class="c">#   def is_authenticated():</span>
+<span class="c">#       ...</span>
+<span class="n">USER_MODEL</span> <span class="o">=</span> <span class="n">setting</span><span class="p">(</span><span class="s">&#39;SOCIAL_AUTH_USER_MODEL&#39;</span><span class="p">)</span> <span class="ow">or</span> \
+             <span class="n">setting</span><span class="p">(</span><span class="s">&#39;AUTH_USER_MODEL&#39;</span><span class="p">)</span> <span class="ow">or</span> \
+             <span class="s">&#39;auth.User&#39;</span>
+
+
+<div class="viewcode-block" id="UserSocialAuth"><a class="viewcode-back" href="../../../models.html#social_auth.db.django_models.UserSocialAuth">[docs]</a><span class="k">class</span> <span class="nc">UserSocialAuth</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">,</span> <span class="n">UserSocialAuthMixin</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Social Auth association model&quot;&quot;&quot;</span>
+    <span class="n">user</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">USER_MODEL</span><span class="p">,</span> <span class="n">related_name</span><span class="o">=</span><span class="s">&#39;social_auth&#39;</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; システムユーザー </span>
+
+<span class="sd">        - settings.SOCIAL_AUTH_USER_MODEL あるいは</span>
+<span class="sd">        - settings.AUTH_USER_MODEL  あるいは</span>
+<span class="sd">        - auth.User </span>
+
+<span class="sd">        システムユーザー1つに付き、複数のソーシャルアカウント(UserSocialAuth)を持つ事ができる。</span>
+<span class="sd">    &#39;&#39;&#39;</span>
+    <span class="n">provider</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; プロバイダー &#39;&#39;&#39;</span>
+    <span class="n">uid</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; プロバイダーのユーザーID ( providier + uid がユニーク ) &#39;&#39;&#39;</span>
+    <span class="n">extra_data</span> <span class="o">=</span> <span class="n">JSONField</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="s">&#39;{}&#39;</span><span class="p">)</span>
+
+    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
+        <span class="sd">&quot;&quot;&quot;Meta data&quot;&quot;&quot;</span>
+        <span class="n">unique_together</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;provider&#39;</span><span class="p">,</span> <span class="s">&#39;uid&#39;</span><span class="p">)</span>
+        <span class="n">app_label</span> <span class="o">=</span> <span class="s">&#39;social_auth&#39;</span>
+
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuth.get_social_auth"><a class="viewcode-back" href="../../../models.html#social_auth.db.django_models.UserSocialAuth.get_social_auth">[docs]</a>    <span class="k">def</span> <span class="nf">get_social_auth</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">provider</span><span class="p">,</span> <span class="n">uid</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;     provider + uid で一意に決まる UserSocialAuth を返す</span>
+
+<span class="sd">            :return:    UserSocialAuth (見つからなかったら None)</span>
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s">&#39;user&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">provider</span><span class="o">=</span><span class="n">provider</span><span class="p">,</span>
+                                                          <span class="n">uid</span><span class="o">=</span><span class="n">uid</span><span class="p">)</span>
+        <span class="k">except</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
+            <span class="k">return</span> <span class="bp">None</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuth.username_max_length"><a class="viewcode-back" href="../../../models.html#social_auth.db.django_models.UserSocialAuth.username_max_length">[docs]</a>    <span class="k">def</span> <span class="nf">username_max_length</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; usernameの長さ &#39;&#39;&#39;</span>
+        <span class="n">field</span> <span class="o">=</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">user_model</span><span class="p">()</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;username&#39;</span><span class="p">)</span>
+        <span class="k">return</span> <span class="n">field</span><span class="o">.</span><span class="n">max_length</span>
+</div>
+    <span class="nd">@classmethod</span>
+<div class="viewcode-block" id="UserSocialAuth.user_model"><a class="viewcode-back" href="../../../models.html#social_auth.db.django_models.UserSocialAuth.user_model">[docs]</a>    <span class="k">def</span> <span class="nf">user_model</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39; 利用しているユーザーモデルクラスを返す</span>
+
+<span class="sd">        .. code-block:: python</span>
+
+<span class="sd">            &gt;&gt;&gt; from social_auth.db.django_models import *</span>
+<span class="sd">            &gt;&gt;&gt; UserSocialAuth.user_model()</span>
+<span class="sd">            &lt;class &#39;django.contrib.auth.models.User&#39;&gt;</span>
+<span class="sd">    </span>
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="k">return</span> <span class="n">UserSocialAuth</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;user&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">rel</span><span class="o">.</span><span class="n">to</span>
+
+</div></div>
+<span class="k">class</span> <span class="nc">Nonce</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">,</span> <span class="n">NonceMixin</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;One use numbers&quot;&quot;&quot;</span>
+    <span class="n">server_url</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; Authz Server URL &#39;&#39;&#39;</span>
+    <span class="n">timestamp</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
+    <span class="sd">&#39;&#39;&#39; タイムスタンプ &#39;&#39;&#39;</span>
+    <span class="n">salt</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; サルト &#39;&#39;&#39;</span>
+
+    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
+        <span class="n">app_label</span> <span class="o">=</span> <span class="s">&#39;social_auth&#39;</span>
+
+
+<span class="k">class</span> <span class="nc">Association</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">,</span> <span class="n">AssociationMixin</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;OpenId account association&quot;&quot;&quot;</span>
+    <span class="n">server_url</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; OP URL &#39;&#39;&#39;</span>
+    <span class="n">handle</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; OpenID ハンドル &#39;&#39;&#39;</span>
+    <span class="n">secret</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">255</span><span class="p">)</span>  <span class="c"># Stored base64 encoded</span>
+    <span class="sd">&#39;&#39;&#39; シークレット &#39;&#39;&#39;</span>
+    <span class="n">issued</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
+    <span class="sd">&#39;&#39;&#39; 発行日時&#39;&#39;&#39;</span>
+    <span class="n">lifetime</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
+    <span class="sd">&#39;&#39;&#39; 有効期限&#39;&#39;&#39;</span>
+    <span class="n">assoc_type</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span>
+    <span class="sd">&#39;&#39;&#39; OpenID アソーシエーションタイプ &#39;&#39;&#39;</span>
+
+    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
+        <span class="n">app_label</span> <span class="o">=</span> <span class="s">&#39;social_auth&#39;</span>
+
+
+<span class="k">def</span> <span class="nf">is_integrity_error</span><span class="p">(</span><span class="n">exc</span><span class="p">):</span>
+    <span class="k">return</span> <span class="n">exc</span><span class="o">.</span><span class="n">__class__</span> <span class="ow">is</span> <span class="n">IntegrityError</span>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_modules/social_auth/decorators.html

+
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    
+    <title>social_auth.decorators &mdash; Social Djagno 1 documentation</title>
+    
+    <link rel="stylesheet" href="../../_static/talks.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/print.css" type="text/css" />
+    <link rel="stylesheet" href="../../_static/fancybox/jquery.fancybox.css" type="text/css" />
+    
+    <script type="text/javascript">
+      var DOCUMENTATION_OPTIONS = {
+        URL_ROOT:    '../../',
+        VERSION:     '1',
+        COLLAPSE_INDEX: false,
+        FILE_SUFFIX: '.html',
+        HAS_SOURCE:  true
+      };
+    </script>
+    <script type="text/javascript" src="../../_static/jquery.js"></script>
+    <script type="text/javascript" src="../../_static/underscore.js"></script>
+    <script type="text/javascript" src="../../_static/doctools.js"></script>
+    <script type="text/javascript" src="../../_static/fancybox/jquery.fancybox.pack.js"></script>
+    <script type="text/javascript" src="../../_static/talks.js"></script>
+    <link rel="top" title="Social Djagno 1 documentation" href="../../index.html" />
+    <link rel="up" title="Module code" href="../index.html" /> 
+  </head>
+  <body>
+
+      <div class="topnav">
+      
+        <p>
+        <a class="uplink" href="../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+      <div class="content">
+        
+
+        
+  <h1>Source code for social_auth.decorators</h1><div class="highlight"><pre>
+<span class="c"># -*- coding: utf-8 -*-</span>
+<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span>
+
+<span class="kn">from</span> <span class="nn">django.core.urlresolvers</span> <span class="kn">import</span> <span class="n">reverse</span>
+
+<span class="kn">from</span> <span class="nn">social_auth.backends</span> <span class="kn">import</span> <span class="n">get_backend</span>
+<span class="kn">from</span> <span class="nn">social_auth.exceptions</span> <span class="kn">import</span> <span class="n">WrongBackend</span>
+
+
+<div class="viewcode-block" id="dsa_view"><a class="viewcode-back" href="../../partial.pipeline.html#social_auth.decorators.dsa_view">[docs]</a><span class="k">def</span> <span class="nf">dsa_view</span><span class="p">(</span><span class="n">redirect_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot; djangos-social-auth ビューをデコレートします</span>
+
+<span class="sd">        - 概要</span>
+
+<span class="sd">            - バックエンドの確認後、バックエンドを取得します。</span>
+<span class="sd">            - バックエンドが見つからないと、HttpResponseServerError を返します。</span>
+<span class="sd">            - redirect_name パラメータを使うと、バックエンドにredirect_urlを指定する事ができます。</span>
+
+<span class="sd">        - 処理</span>
+<span class="sd">            - リダイレクトURLを取得します(なかったら、WSGI Requestオブジェクトのpath )</span>
+<span class="sd">            - リクエストオブジェクトに現在のバックエンドを設定します(みつからないと例外)</span>
+
+<span class="sd">        - その他</span>
+<span class="sd">            - functools.wraps でdocstring が元の関数名になるようにしています</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="k">def</span> <span class="nf">dec</span><span class="p">(</span><span class="n">func</span><span class="p">):</span>
+        <span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
+        <span class="k">def</span> <span class="nf">wrapper</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">backend</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+            <span class="k">if</span> <span class="n">redirect_name</span><span class="p">:</span>
+                <span class="n">redirect</span> <span class="o">=</span> <span class="n">reverse</span><span class="p">(</span><span class="n">redirect_name</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">backend</span><span class="p">,))</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">redirect</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">path</span>
+            <span class="n">request</span><span class="o">.</span><span class="n">social_auth_backend</span> <span class="o">=</span> <span class="n">get_backend</span><span class="p">(</span><span class="n">backend</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span>
+                                                      <span class="n">redirect</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">social_auth_backend</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">WrongBackend</span><span class="p">(</span><span class="n">backend</span><span class="p">)</span>
+            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">request</span><span class="o">.</span><span class="n">social_auth_backend</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="k">return</span> <span class="n">wrapper</span>
+    <span class="k">return</span> <span class="n">dec</span></div>
+</pre></div>
+
+      </div>
+
+      <div class="bottomnav">
+      
+        <p>
+        <a class="uplink" href="../../index.html">Contents</a>
+        </p>
+
+      </div>
+
+    <div class="footer">
+        &copy; Copyright 2012, HDKNR.COM.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>

File socialauth/_sources/about.txt

+==============================================
+Django で Social します
+==============================================
+
+.. contents::
+    :local:
+    :depth: 2
+    :class: talks-contents
+
+django-social-auth いれると簡単
+======================================
+
+- https://github.com/omab/django-social-auth
+- http://django-social-auth.readthedocs.org/en/latest/
+
+OpenID Connect対応するには?
+======================================

File socialauth/_sources/backends.pipeline.txt

+==============================================
+定義済パイプライン
+==============================================
+
+.. contents::
+    :local:
+    :depth: 2
+    :class: talks-contents
+
+social
+=====================================================
+
+associate_user : ソーシャルユーザーとシステムユーザーを紐付けて、次のパイプラインに渡す
+----------------------------------------------------------------------------------------
+
+- 必要であればソーシャルユーザー、ユーザーを新規作成します。
+
+.. autofunction:: social_auth.backends.pipeline.social.associate_user
+
+
+social_auth_user : 既存ソーシャルユーザーとシステムユーザーを次のパイプラインへ渡す
+------------------------------------------------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.social.social_auth_user
+
+load_extra_data : 取得したリソースからユーザーのextra_dataを取り出してソーシャルユーザーに反映
+-----------------------------------------------------------------------------------------------------
+
+- アクセストークンやユーザー識別子、メールアドレスなどその他の情報が含まれます
+- バックエンドプロバイダによって異なります。
+- よって、実際のデータはJSONで保存されます。( OAuthでは決めていない )
+
+.. autofunction:: social_auth.backends.pipeline.social.load_extra_data
+
+user
+=====================================================
+
+get_username : usernameを次のパイプラインへ渡す
+--------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.user.get_username
+
+create_user : ソーシャルユーザーを作成して渡す
+--------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.user.create_user
+
+update_user_details : ユーザー属性を更新する
+--------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.user.update_user_details
+
+
+associate
+=====================================================
+
+
+associate_by_email:  指定されたメールアドレスに対応するソーシャルユーザーを渡す
+--------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.associate.associate_by_email
+
+misc
+=====================================================
+
+save_status_to_session: 現在の social-auth 状態をセッションに保持します 
+------------------------------------------------------------------------
+
+.. autofunction:: social_auth.backends.pipeline.misc.save_status_to_session

File socialauth/_sources/github.reg.txt

+==============================================
+GithubでOAuthトークンを使う
+==============================================
+
+.. contents::
+    :local:
+    :depth: 2
+    :class: talks-contents
+
+アクセストークンを使ってAPIを利用するまでの流れ
+============================================================================================
+
+.. _github.reg.registration:
+
+OAuthのクライアント登録が必要です
+--------------------------------------------------
+
+- OAuthの認証リクエストを行うときに client_idが必要です
+- OAuth Servr(Github) と OAuth Client(Django アプリケーションを関係付けます )
+- 登録するとID(client_id)とパスワード(client_secret)がもらえます(Webアプリのクレデンシャル)。
+- 登録は https://github.com/settings/applications から行います。
+
+.. image:: _static/github.reg/1.png
+
+アプリケーション名とURL
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. image:: _static/github.reg/2.png
+
+Callback URL 重要
+^^^^^^^^^^^^^^^^^^
+
+- OAuth2 の  Authorization Response をアプリケーションに返す先のURLです。
+- :term:`Authorization Request` の :term:`redirect_uri` とのマッチングが行われる文字列になります。
+
+.. image:: _static/github.reg/3.png
+
+登録された
+^^^^^^^^^^^^^^^^^^
+
+- Client ID  /  Client Secret が生成されています.
+
+
+.. image:: _static/github.reg/4.png
+
+クライアント登録するとクレデンシャルをもらえます
+---------------------------------------------------------------
+
+- クレデンシャルの Client ID はユーザーがGithubに対するOAuth :term:`認可リクエスト`  の client_id になります。
+
+    - これにより、ユーザーが認可して発行するアクセストークンの相手がclient_idで示されたWebアプリケーションである事がわかります。
+
+- Client Secret は :term:`認可応答` でもらった「コード」を 認可サーバーで「アクセストークン」に引き換えてもらう時に必要になります。 
+
+    - clinet_id + client_secret で WebアプリケーションはHTTP基本認証で認可サーバーに直接HTTP POSTをおこないます。
+      ( :term:`クライアント認証` /  基本認証以外もプロトコルでは定義されています )
+
+OAuth : 「コードフロー」によるアクセストークンの取得
+---------------------------------------------------------------
+
+- ユーザーがWebアプリに訪れます。
+- GithubのAPIを使ったWebアプリのサービスを受けたいので、「 :term:`認可リクエスト` 」を行います。
+- ブラウザがGithubに認可リクエストを持って訪れるので、ユーザーはGithubにログインし、「Webアプリ」に代理アクセスすることを許可します。
+- ブラウザが :term:`認可応答` を持って、Webアプリに戻ってきます。
+  その中にユーザーがGithubのリソースをWebアプリに代理アクセスすることを許可したこと(grant)を意味する「コード」が含まれています。
+- もらったコードを使ってWebアプリはGithubの「アクセストークン交換場所  (:term:`Token Endpoint`)  」に直接アクセスします。
+- その際、コードを「アクセストークン」に変換する為に、Webアプリはクライアント登録で取得したクレデンシャルで認証を受けます。
+  ( :term:`クライアント認証` )
+- Webアプリが正しく認証されると、コードと引き換えにアクセストークンをもらいます。
+- 以上の流れは「 :term:`コードフロー` 」と呼ばれて、もっともポピュラーといえる :term:`OAuth` のフローです。
+
+WebアプリがGithub APIを使ってサービスを提供する
+-----------------------------------------------------