WordPress post : http://junn.net/archives/601
Reference #1 : https://steemit.com/tutorial/@krnel/tutorial-how-to-add-steemit-login-to-your-site-with-steemconnect
Reference #2 : https://github.com/busyorg/steemconnect
Source :
https://github.com/junn279/steemjs_example/blob/master/steem04.php
https://github.com/junn279/steemjs_example/blob/master/steem04_sub.php
Obviously, it has been already posted in Ref#1 how to use steemconnect for login from my site. But I think there are something to summarize when I was tested.
์ด๋ฏธ ํ๋ฅญํ ์์ ๊ฐ ์ฒซ๋ฒ์งธ ๋ ํผ๋ฐ์ค ์ฌ์ดํธ์ ๋ค์ด๊ฐ๋ฉด ๋ณผ ์ ์๊ณ , (์ฌ์ค ๋ค ์จ์๋ค) ๋ค๋ง ๋ญ๊ฐ ์ ๋ฆฌ๊ฐ ์กฐ๊ธ ๋ ํ์ํ ๋ฏํด์ ํฌ์คํ ํ๊ธฐ๋ก ์๊ฐํ๋ค.
์ธ๋ถ๋ก๊ทธ์ธ์ ์ํด Steemconnect ๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(๋๋ ์ฌ์ดํธ)๋ฅผ ์ด์ฉํ ๊ฒ์ด๋ค. ๋ก๊ทธ์ธ ์ฐฝ์ ๋ค์๊ณผ ๊ฐ์ด ๋์ค๋๋ฐ๋ฐ, ๋น๋ฐ๋ฒํธ๋ posting key๋ฅผ ์ด์ฉํ ์ ์๋ค. posting key๋ฅผ ์ป๋ ๋ฐฉ๋ฒ์ ์ด์ ์์ ์ ์์ ํ์์ง๋ง, ๊ฐ๋จํ๊ฒ๋ Wallet์ Permission์ ๋ค์ด๊ฐ์ posting ์ show private key๋ฅผ ๋๋ฌ์ ๊ตฌํ ์ ์๋ค.
For outside login, we can use Steemconnect library (or site). Login window is as below, we can use posting key as password. Easily, we can get posting key in Wallet of Steemit.com, and click Permissions and click Show Private Key Button.
Posting Key๋ฅผ ์ด์ฉํด์ ๋ก๊ทธ์ธ์ด ๊ฐ๋ฅํ๋ค.
Now we setup the App,
์ฑ์ ์ธํ ํ๊ฒ๋๋๋ฐ, ์ฌ๊ธฐ์ ์กฐ๊ธ ์ ๋งคํ? ๋ถ๋ถ์ด, ์ผ๋จ ๋ด ์์ด๋๊ฐ ๊ณง App ID๊ฐ ๋๋ค. ๋ง์ฝ ‘์๋น์คํ๋ ์ฑ’์ ์ด๋ฆ์ด ๋ด ์์ด๋๊ฐ ์๋๊ธธ ์ํ๋ค๋ฉด https://steemit.com/news/@timcliff/new-tool-from-busy-org-create-new-steem-blockchain-accounts-with-steemconnect ๋ฅผ ์ฐธ์กฐํ๊ฑฐ๋, ์์ด๊ฐ ์ด๋ ต๊ฒ ๋๊ปด์ง์๋ ๋ถ์ ๋ด๊ฐ ์ด ๋ฉ๋ด์ผ https://steemit.com/kr/@junn/391 ์ 4๋ฒ ํํธ๋ฅผ ์ฐธ์กฐํ์ฌ, App ์ ์ฉ ID๋ฅผ ๋ฐ๋ก ๋ง๋ค๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค.
App ID is same as my steemit ID. So if you want to use another ID for your App, it will be good to create new ID via steemconnect (example : https://steemit.com/news/@timcliff/new-tool-from-busy-org-create-new-steem-blockchain-accounts-with-steemconnect)
(1) Author
์์งํ ์ ๋ชจ๋ฅด๊ฒ ๋ค, ๋ด ID์ ๋ค๋ฅธ ๋ฌธ๊ตฌ๋ฅผ ๋ฃ์ด๋ดค๋๋ฐ, ์งํ์์๋ ๋ฌธ์ ๊ฐ ์๋ค.
I don’t know how ‘Author’ plays a role. I putย text other than my ID(junn), there is no problem.
(2) Request Permission
App์ ํตํด ๋ก๊ทธ์ธ ํ๋ ์ฌ๋๋ค์๊ฒ ์์ฒญํ๋ ๊ถํ์ด๋ค. ์ฆ Post์ ์ฒดํฌ๋ฅผ ํด๋์ผ, ์ถํ ๋ก๊ทธ์ธํ ์ฌ์ฉ์๊ฐ App์ ํตํด Steem์ผ๋ก ํฌ์คํ ์ด ๊ฐ๋ฅํ๋ค๋ ์๋ฏธ์ผ ๊ฒ์ผ๋ก ํ๋จ๋๋ค.
Literally, request permission when users log in through this app. If you check ‘Post’, then user could ‘post’ their posting through your app.
(3) Allowed origin
๋ก๊ทธ์ธ์ด ์์ฒญ๋๋ ๋๋ฉ์ธ์ด๋ค. ์๋ฅผ ๋ค๋ฉด ๋ก๊ทธ์ธ ์์ฒญํ์ด์ง๊ฐ http://junn.net/steem04.php ๋ผ๋ฉด, junn.net ๋๋ฉ์ธ์ด allowed origin์ผ๋ก ๋ฑ๋ก์ด ๋์ด์ผ ํ๋ค.
You put origin domain in which request login. If you call login part from ‘http://junn.net/steem04.php’, ‘junn.net’ must be listed.
(4) Allowed redirect urls
๋ก๊ทธ์ธ ํ์ redirection๋๋ ์ฃผ์์ด๋ค. ์๋ฐ์คํฌ๋ฆฝํธ ์์์ ์ค์ ํ๊ฒ ๋๋๋ฐ, ๊ทธ ์ฃผ์๊ฐ ์ ํํ ์ด url ๋ฆฌ์คํธ์ ์์ด์ผ ํ๋ค. http://junn.net/steem04.php์์ ๋ก๊ทธ์ธ์ ์์ฒญํ๊ณ , ์ฑ๊ณต์ http://junn.net/steem04_sub.php ์ด๋ผ๋ ๊ณณ์ผ๋ก ์ด๋ํ๋ค๋ฉด, http://junn.net/steem04_sub.php ์ด ์ ๋ฆฌ์คํธ ์์ ์์ด์ผ ํ๋ค.
Redirection address will be set in javascript page, the exact address must be listed. If you want redirect to ‘http://junn.net/steem04_sub.php’ after login, ‘http://junn.net/steem04_sub.php’ should be listed.
์ด๋ก์จ ์ฑ ์ธํ ์ ์ข ๋ฃ.
https://pastebin.com/xJAs1tbc ๊ฐ ๊ธฐ์์ฑ๋ ์์ ์ด๋ค (๋ด๊ฐ ๋ง๋ ๊ฒ์ด ์๋). ๊ทธ๋์ ์ข ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก, ๋ค๋ฅธ OAuth ์ฑ ์ฒ๋ผ ์์ฐฝ์ ๋์์ ๋ก๊ทธ์ธ์ ์๋ํ๋ ์์ค๋ฅผ ์ ์ํ๋ค.
https://pastebin.com/xJAs1tbc is an example that has already been made. But I approached in different way, in which open new window and try to login.
Test :
Source:
https://github.com/junn279/steemjs_example/blob/master/steem04.php
https://github.com/junn279/steemjs_example/blob/master/steem04_sub.php
39์ค์ ๋ก๊ทธ์ธ์ ๋๋ฅด๋ฉด 33์ค์ redirect function์ด ์คํ๋๋ฉด์ ์์ฐฝ์ด ์ด๋ฆฐ๋ค.
Click login (39th line), redirect function runs.(33th)
์ด ์ ์ฐฝ์๋ 20์ค์์ ๊ฐ์ ธ์จ loginURL์ด ์ด๋ฆฌ๋๋ฐ, ์ด login URL์ 15์ค์ initialize ํจ์๋ฅผ ํตํด ๋ถ๋ฌ์ค๊ฒ ๋๋ค. ์ด ํจ์๋ฅผ ์ธํ ํ๋ 16,17์ค์ ๋ด์ฉ์ ์์ ์ค์ ํ App์ ์ ๋ณด์ ๋์ผํด์ผํ๋ค. 23-31์ค์ ๋ก๊ทธ์ธ์ด ์ฑ๊ณตํ ๊ฒฝ์ฐ์ ์คํ๋๋ ํจ์์ด๋ค.
New window load login page (loginURL;20th line), this url is loaded through initialize function(15th line). Initial variables are in 16th,17th line, must match to the information of the App which we’ve set above. 23-31st line will be executed when login is successful.
์๋ ์๋ steem04_sub.php์์๋ ๋ก๊ทธ์ธ์ฐฝ์ด ์ด๋ฆฐ๋์ ์ฝ๋ฐฑ๋๋ ์ฃผ์์ธ๋ฐ,(์ฆ ๋ก๊ทธ์ธ์ด ์ฑ๊ณตํ๋ฉด ๋ฐ๋๋) ๋ฐ๋ผ์ ๋ก๊ทธ์ธ์ด ๋ ์ดํ 16-21์ค์ด ์คํ๋๋ฉฐ, ์ด ์๋ก ๋ฌ ์ฐฝ์ ๋ซํ๊ณ , ์ด ์ฐฝ์ ์ฐ(steem04.php)๋ฅผย reload ํจ์ผ๋ก์ steem04.php์ 23-31 ์ค์ด ์คํ๋๊ฒ ๋๋ ๊ฒ์ด๋ค.
steem04_sub.php is redirect page which is loaded after successful login, 16th-21st line is run after login. So this page will be closed, refresh opener page(steem04.php). And then we can run 23rd-31st line of steem04.php.
๋ก๊ทธ์ธ์ด ์๋ฃ๋๋ฉด ์๋์ ๊ฐ์ด ๋ฐ๋๋ฉด์
After login, we can see as below,
์ฝ์์๋ ๋ค์๊ณผ ๊ฐ์ด ๋ฌ๋ค.
We can get the information of user from console.
์ด ๋ค์์ ์๋ง userId ๋ฐ token์ ์ด์ฉํด์ Post, vote, follow ๋ฑ์ ํ๋ ๊ณผ์ ์ผ ๊ฒ์ด๋ค.
May next work is Posting, voting, following using this userID and token.