ドキュメントにある"OAuth2.0とFacebook"の項目。
これはloalhostではできないと思ったが、できる。
Facebook DeveloperサイトのWebsiteのSite URL:を「http://127.0.0.1:8000」にしてたならOK
そうしないと「Invalid redirect_uri」になる。
・web2pyでまた実験
下準備(Macの場合)
export FB_ID="Facebookのdevelper ID" export FB_SECRET="Facebookのsecret code"
・これはmodels/db.py
import os from facebook import GraphAPI, GraphAPIError from gluon.contrib.login_methods.oauth20_account import OAuthAccount ## extend the OAUthAccount class class FaceBookAccount(OAuthAccount): """OAuth impl for FaceBook""" YOUR_CLIENT_ID = os.environ.get('FB_ID', "default") YOUR_CLIENT_SECRET = os.environ.get('FB_SECRET', "default") AUTH_URL="https://graph.facebook.com/oauth/authorize" TOKEN_URL="https://graph.facebook.com/oauth/access_token" def __init__(self, g): OAuthAccount.__init__(self, g, self.YOUR_CLIENT_ID, self.YOUR_CLIENT_SECRET, self.AUTH_URL, self.TOKEN_URL) self.graph = None # override function that fetches user info def get_user(self): "Returns the user using the Graph API" if not self.accessToken(): return None if not self.graph: self.graph = GraphAPI((self.accessToken())) try: user = self.graph.get_object("me") return dict(first_name = user['first_name'], last_name = user['last_name'], username = user['id']) except GraphAPIError: self.session.token = None self.graph = None return None ## use the above class to build a new login form auth.settings.login_form=FaceBookAccount(globals())
Loginボタンを何度押してもLoginのまま(すでにFacebookでログインしていたら。認証画面に飛ばない。)
これはどうにかなるのか?
↓
・Authはアプリケーションを作成した時点で、db.py に次のように定義されていると思います。↓
・db.py
auth = Auth(db, hmac_key=Auth.get_or_create_key())
・facebookのIDはe-mailでなくusernameで設定するようなので、テーブル定義のパラメータを指定するため、もともとあった「define_tables」を次のように変更します。↓
・db.py
auth.define_tables(username=True)
・Facebookが認証してくれるのに新規登録のメニューやパスワード変更など
が出てしまいおかしい
追記する↓
・db.py
auth.settings.actions_disabled = ['change_password', 'request_reset_password', 'retrieve_username', 'register']
web2py Google グループのやりとりを参考に
項目は
web2py docsを参考にした。
・トップの変なメニューを消す
・views\default\index.html
こうする
{{left_sidebar_enabled,right_sidebar_enabled=False,True}}
↓
{{left_sidebar_enabled,right_sidebar_enabled=False,False}}
・TopページにあるShareを消す
・views\layout.html
divタグ内の以下をコメントアウトして修正しました。
<!--a class="a2a_dd" href="http://www.addtoany.com/share_save">Share</a-->