質問編集履歴
1
詳細の追記です
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,257 @@
|
|
37
37
|
ただ、この仕様がセキュリティー上良くないことなのか分かりません。
|
38
38
|
|
39
39
|
その点でも助言等頂けると助かります。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
<追記 2018/4/24>
|
44
|
+
|
45
|
+
ご返信ありがとうございます。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
質問だけで詳細を記載していなかったので、追記します。
|
50
|
+
|
51
|
+
サイトには独自の会員登録があります。(PHP + MysQL)
|
52
|
+
|
53
|
+
それとは別にFacebookログインを追加で実装したいんです。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
現在は、SDKを使用して上記の状態です。
|
58
|
+
|
59
|
+
初めてFacebookログインしたときは、フォームに移動し、
|
60
|
+
|
61
|
+
会員登録に必要な項目を入力して登録完了になります。
|
62
|
+
|
63
|
+
その後は、facebookログインボタンを押すと、ログイン状態になります。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
ただ「食べログ」のように、すでにFacebookにログインした状態であれば、
|
68
|
+
|
69
|
+
サイトにアクセスした時にサイト内でログインした状態に自動で切り替わるようにしたいのです。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
一応Javascriptでのやり方は、どこでか忘れてしまったのですが、
|
74
|
+
|
75
|
+
以下の内容で「UserID」の取得は出来ました。
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```<script>
|
80
|
+
|
81
|
+
// This is called with the results from from FB.getLoginStatus().
|
82
|
+
|
83
|
+
function statusChangeCallback(response) {
|
84
|
+
|
85
|
+
console.log('statusChangeCallback');
|
86
|
+
|
87
|
+
console.log(response);
|
88
|
+
|
89
|
+
// The response object is returned with a status field that lets the
|
90
|
+
|
91
|
+
// app know the current login status of the person.
|
92
|
+
|
93
|
+
// Full docs on the response object can be found in the documentation
|
94
|
+
|
95
|
+
// for FB.getLoginStatus().
|
96
|
+
|
97
|
+
if (response.status === 'connected') {
|
98
|
+
|
99
|
+
// Logged into your app and Facebook.
|
100
|
+
|
101
|
+
testAPI();
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
FB.getLoginStatus(function(responsezz) {
|
106
|
+
|
107
|
+
console.log(responsezz);
|
108
|
+
|
109
|
+
if (response.status === 'connected') {
|
110
|
+
|
111
|
+
// FBにログインしてて,このユーザはアプリ認証もとってる.
|
112
|
+
|
113
|
+
//ユーザーIDを取得accessToken
|
114
|
+
|
115
|
+
alert(responsezz.authResponse.userID);
|
116
|
+
|
117
|
+
var fbUid = responsezz.authResponse.userID;
|
118
|
+
|
119
|
+
} else if (response.status === 'not_authorized') {
|
120
|
+
|
121
|
+
// FBにログインはしてるけど,このアプリの認証はない.
|
122
|
+
|
123
|
+
} else {
|
124
|
+
|
125
|
+
// FBにログインしてない
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
} else {
|
134
|
+
|
135
|
+
// The person is not logged into your app or we are unable to tell.
|
136
|
+
|
137
|
+
document.getElementById('status').innerHTML = 'Please log ' +
|
138
|
+
|
139
|
+
'into this app.';
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
// This function is called when someone finishes with the Login
|
148
|
+
|
149
|
+
// Button. See the onlogin handler attached to it in the sample
|
150
|
+
|
151
|
+
// code below.
|
152
|
+
|
153
|
+
function checkLoginState() {
|
154
|
+
|
155
|
+
FB.getLoginStatus(function(response) {
|
156
|
+
|
157
|
+
statusChangeCallback(response);
|
158
|
+
|
159
|
+
});
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
window.fbAsyncInit = function() {
|
166
|
+
|
167
|
+
FB.init({
|
168
|
+
|
169
|
+
appId : '●●●●●●●●●●●●●●●●●●',
|
170
|
+
|
171
|
+
cookie : true, // enable cookies to allow the server to access
|
172
|
+
|
173
|
+
// the session
|
174
|
+
|
175
|
+
xfbml : true, // parse social plugins on this page
|
176
|
+
|
177
|
+
version : 'v2.12' // use graph api version 2.8
|
178
|
+
|
179
|
+
});
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
// Now that we've initialized the JavaScript SDK, we call
|
184
|
+
|
185
|
+
// FB.getLoginStatus(). This function gets the state of the
|
186
|
+
|
187
|
+
// person visiting this page and can return one of three states to
|
188
|
+
|
189
|
+
// the callback you provide. They can be:
|
190
|
+
|
191
|
+
//
|
192
|
+
|
193
|
+
// 1. Logged into your app ('connected')
|
194
|
+
|
195
|
+
// 2. Logged into Facebook, but not your app ('not_authorized')
|
196
|
+
|
197
|
+
// 3. Not logged into Facebook and can't tell if they are logged into
|
198
|
+
|
199
|
+
// your app or not.
|
200
|
+
|
201
|
+
//
|
202
|
+
|
203
|
+
// These three cases are handled in the callback function.
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
FB.getLoginStatus(function(response) {
|
208
|
+
|
209
|
+
statusChangeCallback(response);
|
210
|
+
|
211
|
+
});
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
};
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
// Load the SDK asynchronously
|
220
|
+
|
221
|
+
(function(d, s, id) {
|
222
|
+
|
223
|
+
var js, fjs = d.getElementsByTagName(s)[0];
|
224
|
+
|
225
|
+
if (d.getElementById(id)) return;
|
226
|
+
|
227
|
+
js = d.createElement(s); js.id = id;
|
228
|
+
|
229
|
+
js.src = "https://connect.facebook.net/en_US/sdk.js";
|
230
|
+
|
231
|
+
fjs.parentNode.insertBefore(js, fjs);
|
232
|
+
|
233
|
+
}(document, 'script', 'facebook-jssdk'));
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
// Here we run a very simple test of the Graph API after login is
|
238
|
+
|
239
|
+
// successful. See statusChangeCallback() for when this call is made.
|
240
|
+
|
241
|
+
function testAPI() {
|
242
|
+
|
243
|
+
console.log('Welcome! Fetching your information.... ');
|
244
|
+
|
245
|
+
FB.api('/me', function(response) {
|
246
|
+
|
247
|
+
console.log('Successful login for: ' + response.name);
|
248
|
+
|
249
|
+
document.getElementById('status').innerHTML =
|
250
|
+
|
251
|
+
'Thanks for logging in, ' + response.name + '!';
|
252
|
+
|
253
|
+
});
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
</script>
|
260
|
+
|
261
|
+
```
|
262
|
+
|
263
|
+
これで気になったのが、「appId」がそのままソースに出ているのですが、
|
264
|
+
|
265
|
+
これはセキュリティー上問題ないのでしょうか?
|
266
|
+
|
267
|
+
(他のサイトでも見かけたので、気にしすぎかもしれませんが・・・・)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
あと、Javascriptで「UserID」を取得して、この内容をPHPに移して会員認証をしたいのですが、
|
272
|
+
|
273
|
+
自分がJavascriptをまだよくわかっていないので、
|
274
|
+
|
275
|
+
「$.ajax」やJSONを使うのは分かっても、そこからデータを飛ばすのが、
|
276
|
+
|
277
|
+
どうしても出来ません。
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
質問内容がズレてきているかもしれませんが、
|
282
|
+
|
283
|
+
最初に「PHPで同じようにする方法が分からず困ってます」と書きましたが、
|
284
|
+
|
285
|
+
それは前述の理由と、自分がPHPならまだ分かるという理由です。
|
286
|
+
|
287
|
+
JavaScript SDKでも構いません。
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
長文になり申し訳ありませんが、
|
292
|
+
|
293
|
+
何卒よろしくお願いします。
|