From bd5fa912236cf6b1ff93372ca880ff4eea8f6671 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 21:51:02 +0530 Subject: [PATCH 01/50] feat: started Twitter OAuth --- src/Auth/OAuth/Twitter.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Auth/OAuth/Twitter.php diff --git a/src/Auth/OAuth/Twitter.php b/src/Auth/OAuth/Twitter.php new file mode 100644 index 0000000000..e69de29bb2 From 55f39af302a7e8175b216174c5d49ca8b1ff8c53 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 21:51:27 +0530 Subject: [PATCH 02/50] chore: added twitter icon --- public/images/oauth/twitter.png | Bin 0 -> 3227 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public/images/oauth/twitter.png diff --git a/public/images/oauth/twitter.png b/public/images/oauth/twitter.png new file mode 100644 index 0000000000000000000000000000000000000000..320a807f71029b77788c2f9281bdbb1a49ba94e0 GIT binary patch literal 3227 zcmbtXc{tSH9{yTpEDgpQLe?ay88dc;n8uK0tck3H(U2wkl5IkwkbPgWhmb5;o1c9t zLs}5oVyux}xzls+Klk5zpR>H@^Eu}|=RD7O&vQQKv7tVig_)lj000(@ww4hUaeoUV zEww%kqotz)y|ad%1_0DPJ9A zXFal8u&UG!u)Qu?3po9o^4m(EQ$0)`+7=I}NF52-0A&sM9cqKY8>5F}m}dqG-NVTjkwjL6h-10@>? zT}(EUxe>uUx+j9Vfl7|P{u;#1#1(E>z2&OVU|!}Y!nyoV`@I+QF-$|_u5;8 z&G{bRji>u-%BfM;EX<8xA1fB$XjL*Squ38 zVi?X(hx1i2(&b{ca(nX35zeR+)`WN9CMOhfY8<9`1im3+ZoV1+j!#bH-A2Q)A z^g=|?V9qo4_v^FGH1(7;h}9gM6vSlUa663{liZc>S_6y;w8e~>iO*BmNZvRWgV^yz zV$w~_j;V9`q?5|0TSlDQ-a|9q2d#nbzt;A))~_XsU98CucxA2yC8`(I_tjIn|50_@ zkj*W7RhfLEl^NdG$)5i@L@GQttaKtq%_`LrsmG$0B-Z;>&@WZN7u^xk_`0nZxzq;} zjVxR;bnt4pt*SZgSL?T#N$!|@r<~@E64VpdK5qLbuuz(M?z@I!vE z<7!_JM-*DtC(hoB^n&y6ARfRic{EV9u=K$ z6W59ZJs&@(z}+rq;dAg3E$9g_-heOYS}q>4L^$Yo&L4wq@7K5fwsQ8(@c=0Yw>uWk zY-HU)l_U+w#(mqaO*5q*PPdZCJ@x(m(|y5<d>Ez$s>b7T?y z6&>80^{1D?$E_G+CTbz?v@U2XkoH6;B1Gg{K=|>*e&zj~^<>ds$r%7j3}pu9`u^@_ zMpRiB&)vtqd1>ut!Oo%MvsjQF5=7;?t&k;MQBb0w{l~eh=0D7XYdpq~rLG^iJ@CRz z+gcM4Qp$MJ`M5|73Ldldu+;k3Kxfdpa)FdM(^gbs+Uo+Un3|-}!Bgv_?3%9DPlA_P zPExP51rwU=&0oKrfr?!1Pk|zvdhMgjUhu*bj?tewbkx;!=VHsdr4q7dTQl?LB^9&+uW`=Sc(S-h)JheFl8=D z2yUKd45U2YCTBbq>y*q>k#CvAPRx#yGe*c6`Uahwek<{UPP%E|0{UJbTg5e1{^J(1 zl*E%U!2eubSaztcF!`FEMHKeOT$}Ijh2BLQtL3k4(d@6v!=~kh^S>1lM$A5CvjCZ% zuvyl;$q+>G9pNwhoz{;4wK+qC#Iw+TNA?fKOWB3J@}RWFfx{}JopNJ(et!H!=5VQa zff9OHNx4G9ARfSt=fdh2uS|LJB_&-Al|?*%mM@{#hB_dGcJ$#Dj({6HcN zJ##Fx^AJr;j;v)+9M{SaL0m_N#(Zv?jz3H?ydc^S9Czt6OG91P8=-k-9YX2b?Q}<8 z5GqS$cS%3Kz;*T(3o#+*OpH)MM$i84(e=0;swx#{JdEGMcULb@q;zj^NW=Y` zWUV8IM!L@W5z9-1R&G)H^5JOrjmP)>9c>pkw8_{~N+~A^N_^Hb9J;@9uXI~*0iFyJ zmM!yKj=WO8l@h*cBjmp{wzZ>qq1zv>vj$3YmpQMqdkv2%kBx$ArCUe}rTII2A?_}>~P{D*PTF=xqH;SZkLnQUOtYaiGfhA1wIUFD%YGW zwx@_VAXV$&%WPxM%uQCmYk`EE}!eZ@2Z-pS-j@v8BZG z-?YYt#)Pgz%-7@BJSu%KAGDpHaN7<_<{gxs^!4P!72cF2=rn9&vMw;@t1W!UmoSJI z8m>+oys}gBi8<&^ZfyBkU!q#*WQ`HAcE+48(#whT zwnPpedRN5sSfz?{iBX^Q0^QaCnQfw7Uwb#_J^uSzfJ)#n>0CtGb+(-(%Csl!QLHh; zvEDhFnHO&}T9j_nkFq%VF3mSe@cO5K7d^+n zF1i?9VgfHqBf@t07v4!xRE)<_da{1rUA4bGR_W8!s_}Y=>#K67hoXTEGIwSQe#a05 zyd>rx276o>;5P&3^L9N`tij)`I=EBcvnspeo?r05)FNH1>r$4hHoK?VG0Y zJDS?q=?Y^I1+8s^iw!R>dfd@L!-d;foqi!wQQo>A%0# zgKH*1t_9OX6tPAhdJ7-5D XM>|}AXTRg$9|M3v>1$Qru#NZ^Xg%0x literal 0 HcmV?d00001 From 8829dd0f8513fc2aa80eff2796d0a2f84ac8c2af Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 6 Oct 2019 21:52:54 +0530 Subject: [PATCH 03/50] chore: added twitter to providers0 --- app/config/providers.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/config/providers.php b/app/config/providers.php index 140dbeaf6f..7caef0c51f 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -71,4 +71,9 @@ return [ 'icon' => 'icon-vk', 'enabled' => true, ], + 'twitter' => [ + 'developers' => 'https://developer.twitter.com/', + 'icon' => 'icon-twitter', + 'enabled' => true, + ], ]; From 061f4d4836f8dd9ef2a73b4f1d7315b0a5a61466 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 8 Oct 2019 01:09:01 +0530 Subject: [PATCH 04/50] chore: disabled twitter --- app/config/providers.php | 2 +- app/controllers/auth.php | 3 --- src/Auth/OAuth.php | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/config/providers.php b/app/config/providers.php index 7caef0c51f..3e609e1fd5 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -74,6 +74,6 @@ return [ 'twitter' => [ 'developers' => 'https://developer.twitter.com/', 'icon' => 'icon-twitter', - 'enabled' => true, + 'enabled' => false, ], ]; diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 849f783113..32cdf4a6cb 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -730,9 +730,6 @@ $utopia->get('/v1/auth/oauth/:provider/redirect') $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); - // Uncomment this while testing amazon oAuth - // $state = html_entity_decode($state); - $appId = $project->getAttribute('usersOauth'.ucfirst($provider).'Appid', ''); $appSecret = $project->getAttribute('usersOauth'.ucfirst($provider).'Secret', '{}'); diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index a96ebb7a68..87991f4e40 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -78,16 +78,16 @@ abstract class OAuth */ abstract public function getUserName(string $accessToken):string; + // The parseState function was designed specifically for Amazon OAuth Adapter to override. // The response from Amazon is html encoded and hence it needs to be html_decoded before // json_decoding - /** * @param $state * - * @return json + * @return string */ - public function parseState(string $state) + public function parseState(string $state): string { return json_decode($state, true); } From deb793cb6adfbdff955bd64787427fdca044862d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 8 Oct 2019 15:37:36 +0530 Subject: [PATCH 05/50] feat: merge-commit --- CHANGES.md | 8 ++++++-- docs/references/users/delete-user-session.md | 1 + docs/references/users/update-user-prefs.md | 1 + docs/services/account.md | 6 +++++- docs/services/auth.md | 4 ++-- docs/services/avatars.md | 6 +++++- docs/services/database.md | 6 ++---- docs/services/locale.md | 6 +++++- docs/services/storage.md | 2 +- docs/services/teams.md | 4 ++-- docs/services/users.md | 2 +- 11 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 docs/references/users/delete-user-session.md create mode 100644 docs/references/users/update-user-prefs.md diff --git a/CHANGES.md b/CHANGES.md index 3f97b37063..81f8606070 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ -# Version 0.3.0 (PRE-RELEASE) +# Version 0.3.0 (PRE-RELEASE) - PLANNED -## Planned Issues +## Features * Added 7 new locales for locale service and email templates (af, ar, cz, hu, lt, no, ru, si, sv, ta, vi, zh-cn, zh-tw) * New users service routes to allow updates pref and name update @@ -11,6 +11,10 @@ * Allow electron apps to not pass origin header * New OAuth adapters (Amazon, Dropbox, Microsoft, Slack, VK) +## Breaking Changs + +* users/deleteUsersSession method name changed to users/deleteUserSession in all SDKs for better consistency + # Version 0.2.0 (PRE-RELEASE) ## Features diff --git a/docs/references/users/delete-user-session.md b/docs/references/users/delete-user-session.md new file mode 100644 index 0000000000..7ce030a4a3 --- /dev/null +++ b/docs/references/users/delete-user-session.md @@ -0,0 +1 @@ +Delete user sessions by its unique ID. \ No newline at end of file diff --git a/docs/references/users/update-user-prefs.md b/docs/references/users/update-user-prefs.md new file mode 100644 index 0000000000..b61a54c6a6 --- /dev/null +++ b/docs/references/users/update-user-prefs.md @@ -0,0 +1 @@ +Update user preferences by its unique ID. You can pass only the specific settings you wish to update. \ No newline at end of file diff --git a/docs/services/account.md b/docs/services/account.md index cecc3e2393..54985c7de0 100644 --- a/docs/services/account.md +++ b/docs/services/account.md @@ -1 +1,5 @@ -The account service allow you to fetch and update information related to the currently logged in user. You can also retrieve a list of all the user sessions across different devices and a security log with the account recent activity. \ No newline at end of file +The account service allows you to fetch and update information related to the currently logged-in user. You can use the service to retrieve a list of all the user sessions across different devices and a security log with the recent account activity. + +Using the account service, you can also allow the logged-in user to update his account name, email, or passwords. + +This service also exposes an endpoint to save and read [user preferences](/docs/account#updatePrefs) as a key-value object. This feature is handy if you want to allow extra customization in your app. Common usage for this feature may include saving the user preferred locale, timezone, or custom app theme. The usage of this feature is only limited only by your imagination. \ No newline at end of file diff --git a/docs/services/auth.md b/docs/services/auth.md index ea2f2bcb9a..8e18022b27 100644 --- a/docs/services/auth.md +++ b/docs/services/auth.md @@ -1,3 +1,3 @@ -The authentication service allows you to verify users accounts using basic email and password login or with a supported OAuth provider. The auth service also exposes methods to confirm users email account and recover users forgotten passwords. +The authentication service allows you to verify users' accounts using basic email and password login or with a supported OAuth provider. The auth service also exposes methods to confirm users' email account and recover users forgotten passwords. -You can review our currently available OAuth providers from your project console under the **'users'** menu. \ No newline at end of file +You can review and enable our currently available OAuth providers from your project console under the **'users -> providers'** menu. \ No newline at end of file diff --git a/docs/services/avatars.md b/docs/services/avatars.md index a0475bce9a..e0ed2ebbca 100644 --- a/docs/services/avatars.md +++ b/docs/services/avatars.md @@ -1 +1,5 @@ -The avatars service aims to help you complete common and recitative tasks related to your app images, icons and avatars. Using this service we hope to save you some precious time and help you focus on solving your app real challenges. \ No newline at end of file +The avatars service aims to help you complete everyday tasks related to your app images, icons, and avatars. Using this service, we hope to save you some precious time and help you focus on solving your real app challenges. + +The Avatars service allows you to fetch countries' flags, browser icons, payment methods logos, websites favicons, generate QR codes, and manipulate remote images URLs. + +All endpoints in this service allow you to resize, crop, and change the output image quality to best fit in your app both in terms of look and performance. \ No newline at end of file diff --git a/docs/services/database.md b/docs/services/database.md index 84a0aa1b01..30a0f314ea 100644 --- a/docs/services/database.md +++ b/docs/services/database.md @@ -1,7 +1,5 @@ -The database service allows you to create structured document collections, query and filter lists of documents and manage an advanced set of read and write access. - +The database service allows you to create structured document collections, query and filter lists of documents, and manage an advanced set of read and write access. All the data in the database service is stored in JSON format. The service also allows you to nest child documents and use advanced filters to search and query the database just like you would with a classic graph database. - -By leveraging the database permission management you can assign read or write access to the database documents for a specific user, team, user role or even grant public access to all visitors of your project. You can learn more about [how Appwrite handles permissions and role access control](/docs/permissions). \ No newline at end of file +By leveraging the database permission management, you can assign read or write access to the database documents for a specific user, team, user role, or even grant public access to all visitors to your project. You can learn more about [how Appwrite handles permissions and role access control](/docs/permissions). \ No newline at end of file diff --git a/docs/services/locale.md b/docs/services/locale.md index 060d45bf2f..12cde8b8ce 100644 --- a/docs/services/locale.md +++ b/docs/services/locale.md @@ -1 +1,5 @@ -The locale service allow you customize your app based on your user location. Get your user location, IP address, list of countries names, phone codes, currencies and more. This product includes GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com). \ No newline at end of file +The locale service allows you to customize your app based on your users' location. Using this service, you can get your users' location, IP address, list of countries and continents names, phone codes, currencies, and more. + +The user service supports multiple locales. This feature allows you to fetch countries and continents information in your app language. To switch locales, all you need to do is pass the 'X-Appwrite-Locale' header or set the 'setLocale' method using any of our available SDKs. [View here the list of available locales](https://github.com/appwrite/appwrite/blob/master/app/init.php#L13). + +This product includes GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com). \ No newline at end of file diff --git a/docs/services/storage.md b/docs/services/storage.md index 77253b4ee6..8227154638 100644 --- a/docs/services/storage.md +++ b/docs/services/storage.md @@ -2,4 +2,4 @@ The storage service allows you to manage your project files. You can upload, vie Each file is granted read and write permissions to manage who has access to view or manage it. You can also learn more about how to manage your [resources permissions](/docs/permissions). - You can also use the storage file preview endpoint to show the app users preview images of your files. The preview endpoint also allows you to manipulate the resulting image, so it will fit perfectly inside your app. \ No newline at end of file + You can also use the storage service file preview endpoint to show the app users' preview images of your files. The preview endpoint also allows you to manipulate the resulting image so that it will fit perfectly inside your app in terms of size and style. \ No newline at end of file diff --git a/docs/services/teams.md b/docs/services/teams.md index a074be96e8..729975a027 100644 --- a/docs/services/teams.md +++ b/docs/services/teams.md @@ -1,3 +1,3 @@ -The teams' service allows you to group together users of your project and allow them to share read and write access to your project resources, such as, database documents or storage files. +The teams' service allows you to group users of your project and will enable them to share read and write access to your project resources, such as database documents or storage files. -Each user who creates a team becomes the team owner and can delegate the ownership role by inviting a new team member. Only team owners can invite new users to the team. \ No newline at end of file +Each user who creates a team becomes the team owner and can delegate the ownership role by inviting a new team member. Only team owners can invite new users to their team. \ No newline at end of file diff --git a/docs/services/users.md b/docs/services/users.md index b1d24362cd..c3dba6dbec 100644 --- a/docs/services/users.md +++ b/docs/services/users.md @@ -1 +1 @@ -The users' service allows you to to manage your users in admin mode, you can search, block and view your users' current sessions and latest activity. \ No newline at end of file +The users' service allows you to manage your users in admin mode (AKA server-side integration). Use this service to search, block, and view your Users info, current sessions, and latest activities. You can also use the Users service to edit your users' preferences and personal info. \ No newline at end of file From 490aab7bb04823ed215cade265d688e6fce8130d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:00:51 +0400 Subject: [PATCH 06/50] feat: added stackoverflow provider --- app/config/providers.php | 5 +++++ public/images/oauth/stackoverflow.png | Bin 0 -> 3034 bytes 2 files changed, 5 insertions(+) create mode 100644 public/images/oauth/stackoverflow.png diff --git a/app/config/providers.php b/app/config/providers.php index 3e609e1fd5..2e5e8bb410 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -76,4 +76,9 @@ return [ 'icon' => 'icon-twitter', 'enabled' => false, ], + 'stackoverflow' => [ + 'developers' => 'https://developer.twitter.com/', + 'icon' => 'icon-stackoverflow', + 'enabled' => true, + ], ]; diff --git a/public/images/oauth/stackoverflow.png b/public/images/oauth/stackoverflow.png new file mode 100644 index 0000000000000000000000000000000000000000..e9b6c0d31b8ac4ed6263e0728ab38b115fb5e585 GIT binary patch literal 3034 zcmb7Gc{J2tAO4O#vLsoGEQO)5jh$qe8EdlsjIm^$$u47?78xS@E|Mk25?Nvf*_Xqp z859+vkfMgy5+b{I`t$wcJ?DMTJ@-EMdG3AA`J8({_nuFp)eU2A&hwlA0C1a{AZ!@u z^|x~{F~$=D6Eg!?ZW&k@06=3p*P%NrgG+dt*jNC-T^Rr%!~(!RLn6=tAWRtmmfZkA z=LrA^-7ajmzRFl&^Ds9?04IN2N!RmihH~n*2|9#%npz;)zjJb* z(G{Lp=$ZlmPO2%wzz#pX`V{Sd;nO+TdSp;*QZhJ+U;0jIorAsqP@~uY4@t}CTa&46 zlWB$kQs{S$xKE}aGMZ>`R>C5B=Mpj+VzHk|RNxe#^EU+-P4E=TkjRs1V!E>f-gC(O zauaG!>u_hpL1|nLMm_sqjoT{sMkICr8{=zU3z949{QcE=gR@0YK*=b(Y`HWK ztl~ft-cx;d)i%%)fI03eY>&7m)x&d&zxG+=h1<|MOFqaRq#FjZ-44W+Q#q0&V zZJ!`>g>|aePPC-9GOrf5ue^sSq}K;r25FhmvKFl1bu$T||G5H#uGyzv4+lLxPE`)~8SxlVOZ zGHJ|!!VJ^mF}3lmfv|{~PKCJf<~I(!l>Nb#hYU2wlzu$3Px@?iUIa^5H_8jebA`#WXL6foJf9`KA6Y=gFH0!1U&6d(v!Er?u_ijiPl~i-M zzTyg?KyFs#N|(*FMHD~(s6{zIM0AL1vl=2J#HI`PWc>Q_`uiDYW^JUyX?Bf?&*Jw` zrtR?O0pAItY=TDKias=o2Lw14-9HMT*Sj{7511LxL5bz?(E5;J)MGw z>`gILhxF-VsR|-tD;-UyRZ0>6=uJiCRC>~Xm-QFugMijJO@EK$?M=f^Q0b^&aDI8G z=2XoV>V~qHj6z3uK-VAR;huUrYj?SmJ8su&NBZ>UP26&bq_;eNj$9*?LWM$O3lYYw+sI1!6~$jSAqXqmc-3K*DF6QiJx0 z?@8=>VK9mI&mrtl(y#kzJH~acc>dL!WtZw0&#lVm%o5+N9p9OFunG%e=row$Ex4hV z4KwtxbMfX6UTR~A<7?1R+Dl@P#VHTQS4TFHeBIBGf*opXnY}dg-?#!GM*36}i z1lG=)Ie{#^hcra9I-y;-+LwFRjQqwQXT@B$NK0CSPcL;z;V$CjU^npsdIq1%lzype z<_+2=gJbn`;BazgE0XL%~ znC&`x0PMMV(Kz|aeIViO`Nhh3{LqZYuUM@k%dx1GzX>ZB;Hp?52S#E|6(YV0EobUG zD+Uw11J~ee*9}mF@mk7L_1czv)<8yhw|A`?MK-mxY(6~yh= zQQzEaER~r#KOeWt7YsK~9%^3DH@2#+au{244^wCmfsKrY7FK%VJgm~<7x7QB`g4lQ zLvatZL3vB^d?0NJ&*N>b%7iL1S@p4*LgDIdEsd5IsQuxOe>q|*J}lv{cJqlyy?AkV z`z3nCVJ3FmqIOAUa#O-2wNlor6E(OGp1tDP1)VVe5X>iU63}uoEGvdm#(U0FDrID| zsS7LOMhL}MpG&53btFE5iv1JxzEU5-Y3%Gmv4m^H1(Q^$ker@r_9fg^$R+oD;gV$Q zCu!D!Yye>j?J`8<8s3`n1gF-1>lX;!A6;UON_g2LmH^g8Cc2xQrY1hnK0dXGee$V_ zd;f~<9a1hKAzVoVU+S(Z%cKA|R5-e-l{`=S2vTR#T99>v+@tnxA;fu~;+mrL0lCf%dqJdNB0@qg%)4#ISO1ta`fpAl`!B@EB1oX+cDgVTXHgiwT(@(k0 z1tSwxxH@_2)yW(%GoOK&Ketj|zquP#M=Inomf))@3^qpa#P^rr2n literal 0 HcmV?d00001 From 1d34eec44bc642f3fd9cb89066646db4a6befa2a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:05:39 +0400 Subject: [PATCH 07/50] feat: added stackoverflow class --- src/Auth/OAuth/Google.php | 16 +++++++--------- src/Auth/OAuth/Stackoverflow.php | 0 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 src/Auth/OAuth/Stackoverflow.php diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index 42f4357bd7..e28ec68ab4 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -5,15 +5,13 @@ namespace Auth\OAuth; use Auth\OAuth; // Reference Material -// https://developers.google.com/oauthplayground/ -// https://developers.google.com/identity/protocols/OAuth2 -// https://developers.google.com/identity/protocols/OAuth2WebServer -class Google extends OAuth +// https://api.stackexchange.com/docs/authentication +class Stackoverflow extends OAuth { - /** - * @var string - */ - protected $version = 'v4'; + // /** + // * @var string + // */ + // protected $version = 'v4'; /** * @var array */ @@ -24,7 +22,7 @@ class Google extends OAuth */ public function getName(): string { - return 'google'; + return 'stackoverflow'; } /** diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php new file mode 100644 index 0000000000..e69de29bb2 From 4ac8cd50b9536e1f12d028545b51aea21104fe0a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:06:20 +0400 Subject: [PATCH 08/50] fix: fixed changes to Google.php --- src/Auth/OAuth/Google.php | 16 ++-- src/Auth/OAuth/Stackoverflow.php | 132 +++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 7 deletions(-) diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index e28ec68ab4..42f4357bd7 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -5,13 +5,15 @@ namespace Auth\OAuth; use Auth\OAuth; // Reference Material -// https://api.stackexchange.com/docs/authentication -class Stackoverflow extends OAuth +// https://developers.google.com/oauthplayground/ +// https://developers.google.com/identity/protocols/OAuth2 +// https://developers.google.com/identity/protocols/OAuth2WebServer +class Google extends OAuth { - // /** - // * @var string - // */ - // protected $version = 'v4'; + /** + * @var string + */ + protected $version = 'v4'; /** * @var array */ @@ -22,7 +24,7 @@ class Stackoverflow extends OAuth */ public function getName(): string { - return 'stackoverflow'; + return 'google'; } /** diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php index e69de29bb2..42f4357bd7 100644 --- a/src/Auth/OAuth/Stackoverflow.php +++ b/src/Auth/OAuth/Stackoverflow.php @@ -0,0 +1,132 @@ +appID). + '&redirect_uri='.urlencode($this->callback). + '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'. + '&state='.urlencode(json_encode($this->state)). + '&response_type=code'; + } + + /** + * @param string $code + * + * @return string + */ + public function getAccessToken(string $code): string + { + $accessToken = $this->request( + 'POST', + 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'. + 'code='.urlencode($code). + '&client_id='.urlencode($this->appID). + '&client_secret='.urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback). + '&scope='. + '&grant_type=authorization_code' + ); + + $accessToken = json_decode($accessToken, true); + + if (isset($accessToken['access_token'])) { + return $accessToken['access_token']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserID(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['id'])) { + return $user['id']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserEmail(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['email'])) { + return $user['email']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return string + */ + public function getUserName(string $accessToken): string + { + $user = $this->getUser($accessToken); + + if (isset($user['name'])) { + return $user['name']; + } + + return ''; + } + + /** + * @param string $accessToken + * + * @return array + */ + protected function getUser(string $accessToken): array + { + if (empty($this->user)) { + $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.urlencode($accessToken)); + $this->user = json_decode($user, true); + } + + return $this->user; + } +} From c251451957da5f8e73e30dc94816124abe96f635 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:11:49 +0400 Subject: [PATCH 09/50] feat: added stackoverflow reference --- src/Auth/OAuth/Stackoverflow.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php index 42f4357bd7..c0e9ed45b5 100644 --- a/src/Auth/OAuth/Stackoverflow.php +++ b/src/Auth/OAuth/Stackoverflow.php @@ -5,15 +5,15 @@ namespace Auth\OAuth; use Auth\OAuth; // Reference Material -// https://developers.google.com/oauthplayground/ -// https://developers.google.com/identity/protocols/OAuth2 -// https://developers.google.com/identity/protocols/OAuth2WebServer -class Google extends OAuth +// https://api.stackexchange.com/docs/me +// https://api.stackexchange.com/docs/authentication + +class Stackoverflow extends OAuth { - /** - * @var string - */ - protected $version = 'v4'; + // /** + // * @var string + // */ + // protected $version = 'v4'; /** * @var array */ @@ -24,7 +24,7 @@ class Google extends OAuth */ public function getName(): string { - return 'google'; + return 'stackoverflow'; } /** @@ -32,12 +32,11 @@ class Google extends OAuth */ public function getLoginURL(): string { - return 'https://accounts.google.com/o/oauth2/v2/auth?'. + return 'https://stackoverflow.com/oauth?'. 'client_id='.urlencode($this->appID). '&redirect_uri='.urlencode($this->callback). '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'. - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'; + '&state='.urlencode(json_encode($this->state)); } /** From 26071b9a3c20cbffb38a9e0a65c49f4053d27db1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:13:31 +0400 Subject: [PATCH 10/50] feat: added scope --- src/Auth/OAuth/Stackoverflow.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php index c0e9ed45b5..5563cec772 100644 --- a/src/Auth/OAuth/Stackoverflow.php +++ b/src/Auth/OAuth/Stackoverflow.php @@ -10,10 +10,10 @@ use Auth\OAuth; class Stackoverflow extends OAuth { - // /** - // * @var string - // */ - // protected $version = 'v4'; + /** + * @var string + */ + protected $version = 'v2.2'; /** * @var array */ @@ -35,7 +35,7 @@ class Stackoverflow extends OAuth return 'https://stackoverflow.com/oauth?'. 'client_id='.urlencode($this->appID). '&redirect_uri='.urlencode($this->callback). - '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'. + '&scope=private_info'. '&state='.urlencode(json_encode($this->state)); } From 17590846a14fb924b39580ed8b29f42a33fd2316 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 22:25:39 +0400 Subject: [PATCH 11/50] fix: return type of parseState removed --- src/Auth/OAuth.php | 2 +- src/Auth/OAuth/Stackoverflow.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 87991f4e40..780b9175c3 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -87,7 +87,7 @@ abstract class OAuth * * @return string */ - public function parseState(string $state): string + public function parseState(string $state) { return json_decode($state, true); } diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php index 5563cec772..78907748ff 100644 --- a/src/Auth/OAuth/Stackoverflow.php +++ b/src/Auth/OAuth/Stackoverflow.php @@ -39,6 +39,7 @@ class Stackoverflow extends OAuth '&state='.urlencode(json_encode($this->state)); } + /** * @param string $code * @@ -46,6 +47,9 @@ class Stackoverflow extends OAuth */ public function getAccessToken(string $code): string { + var_dump($code); + exit(); + $accessToken = $this->request( 'POST', 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'. From 681acbdffa3d5f284a1e53bbedea840829be041d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 23:22:15 +0400 Subject: [PATCH 12/50] feat: getAccessToken Done --- src/Auth/OAuth/Stackoverflow.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php index 78907748ff..0cbe40337f 100644 --- a/src/Auth/OAuth/Stackoverflow.php +++ b/src/Auth/OAuth/Stackoverflow.php @@ -39,7 +39,7 @@ class Stackoverflow extends OAuth '&state='.urlencode(json_encode($this->state)); } - + /** * @param string $code * @@ -47,22 +47,20 @@ class Stackoverflow extends OAuth */ public function getAccessToken(string $code): string { - var_dump($code); - exit(); - + + $headers[] = 'Content-Type: application/x-www-form-urlencoded'; $accessToken = $this->request( 'POST', - 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'. - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&scope='. - '&grant_type=authorization_code' + 'https://stackoverflow.com/oauth/access_token/json', + $headers, + 'code=' . urlencode($code) . + '&client_id=' . urlencode($this->appID) . + '&client_secret=' . urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback) ); $accessToken = json_decode($accessToken, true); - + if (isset($accessToken['access_token'])) { return $accessToken['access_token']; } From 63571dd52b04053b8431af9ed4880207136fe897 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 23:37:00 +0400 Subject: [PATCH 13/50] feat: removed StackExchange Class --- src/Auth/OAuth/Stackoverflow.php | 133 ------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 src/Auth/OAuth/Stackoverflow.php diff --git a/src/Auth/OAuth/Stackoverflow.php b/src/Auth/OAuth/Stackoverflow.php deleted file mode 100644 index 0cbe40337f..0000000000 --- a/src/Auth/OAuth/Stackoverflow.php +++ /dev/null @@ -1,133 +0,0 @@ -appID). - '&redirect_uri='.urlencode($this->callback). - '&scope=private_info'. - '&state='.urlencode(json_encode($this->state)); - } - - - /** - * @param string $code - * - * @return string - */ - public function getAccessToken(string $code): string - { - - $headers[] = 'Content-Type: application/x-www-form-urlencoded'; - $accessToken = $this->request( - 'POST', - 'https://stackoverflow.com/oauth/access_token/json', - $headers, - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback) - ); - - $accessToken = json_decode($accessToken, true); - - if (isset($accessToken['access_token'])) { - return $accessToken['access_token']; - } - - return ''; - } - - /** - * @param string $accessToken - * - * @return string - */ - public function getUserID(string $accessToken): string - { - $user = $this->getUser($accessToken); - - if (isset($user['id'])) { - return $user['id']; - } - - return ''; - } - - /** - * @param string $accessToken - * - * @return string - */ - public function getUserEmail(string $accessToken): string - { - $user = $this->getUser($accessToken); - - if (isset($user['email'])) { - return $user['email']; - } - - return ''; - } - - /** - * @param string $accessToken - * - * @return string - */ - public function getUserName(string $accessToken): string - { - $user = $this->getUser($accessToken); - - if (isset($user['name'])) { - return $user['name']; - } - - return ''; - } - - /** - * @param string $accessToken - * - * @return array - */ - protected function getUser(string $accessToken): array - { - if (empty($this->user)) { - $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); - } - - return $this->user; - } -} From bffa3f0f7546f4e69366d77a14b97abc8894264c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 23:38:28 +0400 Subject: [PATCH 14/50] feat: removed StackExchange from providers --- app/config/providers.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/config/providers.php b/app/config/providers.php index 2e5e8bb410..3d259baa62 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -75,10 +75,5 @@ return [ 'developers' => 'https://developer.twitter.com/', 'icon' => 'icon-twitter', 'enabled' => false, - ], - 'stackoverflow' => [ - 'developers' => 'https://developer.twitter.com/', - 'icon' => 'icon-stackoverflow', - 'enabled' => true, - ], + ] ]; From 2dbb68f4107cfc2c5b9cafb7df39d45f644fcb2e Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 13 Oct 2019 23:38:58 +0400 Subject: [PATCH 15/50] feat: removed stack overflow image --- public/images/oauth/stackoverflow.png | Bin 3034 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 public/images/oauth/stackoverflow.png diff --git a/public/images/oauth/stackoverflow.png b/public/images/oauth/stackoverflow.png deleted file mode 100644 index e9b6c0d31b8ac4ed6263e0728ab38b115fb5e585..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3034 zcmb7Gc{J2tAO4O#vLsoGEQO)5jh$qe8EdlsjIm^$$u47?78xS@E|Mk25?Nvf*_Xqp z859+vkfMgy5+b{I`t$wcJ?DMTJ@-EMdG3AA`J8({_nuFp)eU2A&hwlA0C1a{AZ!@u z^|x~{F~$=D6Eg!?ZW&k@06=3p*P%NrgG+dt*jNC-T^Rr%!~(!RLn6=tAWRtmmfZkA z=LrA^-7ajmzRFl&^Ds9?04IN2N!RmihH~n*2|9#%npz;)zjJb* z(G{Lp=$ZlmPO2%wzz#pX`V{Sd;nO+TdSp;*QZhJ+U;0jIorAsqP@~uY4@t}CTa&46 zlWB$kQs{S$xKE}aGMZ>`R>C5B=Mpj+VzHk|RNxe#^EU+-P4E=TkjRs1V!E>f-gC(O zauaG!>u_hpL1|nLMm_sqjoT{sMkICr8{=zU3z949{QcE=gR@0YK*=b(Y`HWK ztl~ft-cx;d)i%%)fI03eY>&7m)x&d&zxG+=h1<|MOFqaRq#FjZ-44W+Q#q0&V zZJ!`>g>|aePPC-9GOrf5ue^sSq}K;r25FhmvKFl1bu$T||G5H#uGyzv4+lLxPE`)~8SxlVOZ zGHJ|!!VJ^mF}3lmfv|{~PKCJf<~I(!l>Nb#hYU2wlzu$3Px@?iUIa^5H_8jebA`#WXL6foJf9`KA6Y=gFH0!1U&6d(v!Er?u_ijiPl~i-M zzTyg?KyFs#N|(*FMHD~(s6{zIM0AL1vl=2J#HI`PWc>Q_`uiDYW^JUyX?Bf?&*Jw` zrtR?O0pAItY=TDKias=o2Lw14-9HMT*Sj{7511LxL5bz?(E5;J)MGw z>`gILhxF-VsR|-tD;-UyRZ0>6=uJiCRC>~Xm-QFugMijJO@EK$?M=f^Q0b^&aDI8G z=2XoV>V~qHj6z3uK-VAR;huUrYj?SmJ8su&NBZ>UP26&bq_;eNj$9*?LWM$O3lYYw+sI1!6~$jSAqXqmc-3K*DF6QiJx0 z?@8=>VK9mI&mrtl(y#kzJH~acc>dL!WtZw0&#lVm%o5+N9p9OFunG%e=row$Ex4hV z4KwtxbMfX6UTR~A<7?1R+Dl@P#VHTQS4TFHeBIBGf*opXnY}dg-?#!GM*36}i z1lG=)Ie{#^hcra9I-y;-+LwFRjQqwQXT@B$NK0CSPcL;z;V$CjU^npsdIq1%lzype z<_+2=gJbn`;BazgE0XL%~ znC&`x0PMMV(Kz|aeIViO`Nhh3{LqZYuUM@k%dx1GzX>ZB;Hp?52S#E|6(YV0EobUG zD+Uw11J~ee*9}mF@mk7L_1czv)<8yhw|A`?MK-mxY(6~yh= zQQzEaER~r#KOeWt7YsK~9%^3DH@2#+au{244^wCmfsKrY7FK%VJgm~<7x7QB`g4lQ zLvatZL3vB^d?0NJ&*N>b%7iL1S@p4*LgDIdEsd5IsQuxOe>q|*J}lv{cJqlyy?AkV z`z3nCVJ3FmqIOAUa#O-2wNlor6E(OGp1tDP1)VVe5X>iU63}uoEGvdm#(U0FDrID| zsS7LOMhL}MpG&53btFE5iv1JxzEU5-Y3%Gmv4m^H1(Q^$ker@r_9fg^$R+oD;gV$Q zCu!D!Yye>j?J`8<8s3`n1gF-1>lX;!A6;UON_g2LmH^g8Cc2xQrY1hnK0dXGee$V_ zd;f~<9a1hKAzVoVU+S(Z%cKA|R5-e-l{`=S2vTR#T99>v+@tnxA;fu~;+mrL0lCf%dqJdNB0@qg%)4#ISO1ta`fpAl`!B@EB1oX+cDgVTXHgiwT(@(k0 z1tSwxxH@_2)yW(%GoOK&Ketj|zquP#M=Inomf))@3^qpa#P^rr2n From d5294da9dadb71bca9e3839e595f21b68c478fd8 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 11 Jan 2020 13:26:37 +0530 Subject: [PATCH 16/50] chore: added cache and local storage to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 83cfd4a1ee..16ce41ad7f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ /vendor/ /node_modules/ /storage/uploads/ +/storage/cache +/storage/db +/storage/influxdb /tests/resources/storage/ /.idea/ .DS_Store From a5bfc8668b2ecb30ced7ac17f7a52adbe681b9fe Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 12 Jan 2020 00:33:06 +0530 Subject: [PATCH 17/50] feat: added support for scope parameter in the OAuth route --- app/controllers/auth.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index c19fa55a3e..0b48a09d95 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -4,6 +4,7 @@ global $utopia, $register, $request, $response, $user, $audit, $webhook, $projec use Utopia\Exception; use Utopia\Validator\WhiteList; +use Utopia\Validator\ArrayList; use Utopia\Validator\Text; use Utopia\Validator\Email; use Utopia\Validator\Host; @@ -400,8 +401,9 @@ $utopia->get('/v1/auth/login/oauth/:provider') ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth Provider. Currently, supported providers are: ' . implode(', ', array_keys($providers))) ->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.') ->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.') + ->param('scopes', [], function () { return new ArrayList(new Text(128)); }, 'An array of string where each can be max 128 chars', true) ->action( - function ($provider, $success, $failure) use ($response, $request, $project) { + function ($provider, $success, $failure, $scopes) use ($response, $request, $project) { $callback = $request->getServer('REQUEST_SCHEME', 'https').'://'.$request->getServer('HTTP_HOST').'/v1/auth/login/oauth/callback/'.$provider.'/'.$project->getUid(); $appId = $project->getAttribute('usersOauth'.ucfirst($provider).'Appid', ''); $appSecret = $project->getAttribute('usersOauth'.ucfirst($provider).'Secret', '{}'); From 2660fcfc3b1cbf9c1e8b68212e4a9f9392d3dc0c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 12 Jan 2020 00:39:22 +0530 Subject: [PATCH 18/50] feat: added support for scopes param in OAuth Constructor --- app/controllers/auth.php | 2 +- src/Auth/OAuth.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 0b48a09d95..9ec8c4504a 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -425,7 +425,7 @@ $utopia->get('/v1/auth/login/oauth/:provider') throw new Exception('Provider is not supported', 501); } - $oauth = new $classname($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure]); + $oauth = new $classname($appId, $appSecret, $callback, ['success' => $success, 'failure' => $failure], $scopes); $response->redirect($oauth->getLoginURL()); } diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 780b9175c3..37f0c07dd0 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -24,6 +24,11 @@ abstract class OAuth */ protected $state; + /** + * @var array + */ + protected $scopes; + /** * OAuth constructor. * @@ -31,13 +36,17 @@ abstract class OAuth * @param string $appSecret * @param string $callback * @param array $state + * @param array $scope */ - public function __construct(string $appId, string $appSecret, string $callback, $state = []) + public function __construct(string $appId, string $appSecret, string $callback, $state = [], $scopes) { $this->appID = $appId; $this->appSecret = $appSecret; $this->callback = $callback; $this->state = $state; + $this->scopes = $scopes; + var_dump($scopes); + exit(); } /** From 230b039bbd4b592cf7260e8e00ee28993b9c60c6 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 12 Jan 2020 00:59:22 +0530 Subject: [PATCH 19/50] feat: added methods for adding and getting scopes --- src/Auth/OAuth.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 37f0c07dd0..5a9c1ed14f 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -45,8 +45,6 @@ abstract class OAuth $this->callback = $callback; $this->state = $state; $this->scopes = $scopes; - var_dump($scopes); - exit(); } /** @@ -87,7 +85,26 @@ abstract class OAuth */ abstract public function getUserName(string $accessToken):string; + /** + * @param $scope + * + * @return array + */ + protected function addScope(string $scope){ + // Add a scope to the scopes array if it isn't already present + if (!in_array($scope, $this->scopes)){ + $this->$scopes[] = $scope; + } + } + /** + * @return array + */ + protected function getScopes(){ + return $this->scopes; + } + + // The parseState function was designed specifically for Amazon OAuth Adapter to override. // The response from Amazon is html encoded and hence it needs to be html_decoded before // json_decoding From 074bf1ae509e42a2f9703d2c07bf3920dd4a3fb8 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 12 Jan 2020 17:21:30 +0530 Subject: [PATCH 20/50] feat: applied methods to adapters --- app/controllers/auth.php | 12 ++++++------ app/controllers/shared/api.php | 2 +- src/Auth/OAuth.php | 16 ++++++++-------- src/Auth/OAuth/Bitbucket.php | 23 +++++++++++++++++++---- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 9ec8c4504a..01d5c1ee9f 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -396,8 +396,8 @@ $utopia->get('/v1/auth/login/oauth/:provider') ->label('sdk.description', '/docs/references/auth/login-oauth.md') ->label('sdk.location', true) ->label('sdk.cookies', true) - ->label('abuse-limit', 50) - ->label('abuse-key', 'ip:{ip}') + // ->label('abuse-limit', 100) + // ->label('abuse-key', 'ip:{ip}') ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth Provider. Currently, supported providers are: ' . implode(', ', array_keys($providers))) ->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.') ->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.') @@ -435,8 +435,8 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId') ->desc('OAuth Callback') ->label('error', __DIR__.'/../views/general/error.phtml') ->label('scope', 'auth') - ->label('abuse-limit', 50) - ->label('abuse-key', 'ip:{ip}') + // ->label('abuse-limit', 100) + // ->label('abuse-key', 'ip:{ip}') ->label('docs', false) ->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID') ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider') @@ -454,8 +454,8 @@ $utopia->get('/v1/auth/login/oauth/:provider/redirect') ->label('error', __DIR__.'/../views/general/error.phtml') ->label('webhook', 'auth.oauth') ->label('scope', 'auth') - ->label('abuse-limit', 50) - ->label('abuse-key', 'ip:{ip}') + // ->label('abuse-limit', 100) + // ->label('abuse-key', 'ip:{ip}') ->label('docs', false) ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider') ->param('code', '', function () { return new Text(1024); }, 'OAuth code') diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 020f8d9adf..f0cc1a2c3a 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -9,7 +9,7 @@ global $utopia, $request, $response, $register, $user, $project; $utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) { if (is_null($project->getUid()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) { - throw new Exception('Missing Project UID', 400); + // throw new Exception('Missing Project UID', 400); } $route = $utopia->match($request); diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 5a9c1ed14f..73ca9a6c10 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -27,7 +27,7 @@ abstract class OAuth /** * @var array */ - protected $scopes; + protected $userScopes; /** * OAuth constructor. @@ -36,15 +36,15 @@ abstract class OAuth * @param string $appSecret * @param string $callback * @param array $state - * @param array $scope + * @param array $userScopes */ - public function __construct(string $appId, string $appSecret, string $callback, $state = [], $scopes) + public function __construct(string $appId, string $appSecret, string $callback, $state = [], $userScopes = []) { $this->appID = $appId; $this->appSecret = $appSecret; $this->callback = $callback; $this->state = $state; - $this->scopes = $scopes; + $this->userScopes = $userScopes; } /** @@ -92,8 +92,8 @@ abstract class OAuth */ protected function addScope(string $scope){ // Add a scope to the scopes array if it isn't already present - if (!in_array($scope, $this->scopes)){ - $this->$scopes[] = $scope; + if (!in_array($scope, $this->userScopes)){ + $this->userScopes[] = $scope; } } @@ -101,10 +101,10 @@ abstract class OAuth * @return array */ protected function getScopes(){ - return $this->scopes; + return $this->userScopes; } - + // The parseState function was designed specifically for Amazon OAuth Adapter to override. // The response from Amazon is html encoded and hence it needs to be html_decoded before // json_decoding diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index 902c0a4238..c95d77aeb2 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -14,6 +14,11 @@ class Bitbucket extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $requiredScope = []; + /** * @return string */ @@ -27,10 +32,20 @@ class Bitbucket extends OAuth */ public function getLoginURL(): string { - return 'https://bitbucket.org/site/oauth2/authorize?' . - 'client_id=' . urlencode($this->appID). - '&state=' . urlencode(json_encode($this->state)). - '&response_type=code'; + // add each required scope to the user scopes and pass $this->scopes to the query builder + // var_dump($this->getScopes()); + foreach ($this->requiredScope as $item) { + $this->addScope($item); + } + // var_dump($this->getScopes()); + // exit(); + + return 'https://bitbucket.org/site/oauth2/authorize?' .http_build_query([ + 'response_type' => 'code', + 'client_id' => $this->appID, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state), + ]); } /** From d33ffbbd372d298850a99148dcd3e73a4fcbcc7d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 00:09:09 +0530 Subject: [PATCH 21/50] chore: added back abuse limits --- app/controllers/auth.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 01d5c1ee9f..17ada8bc3a 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -454,8 +454,8 @@ $utopia->get('/v1/auth/login/oauth/:provider/redirect') ->label('error', __DIR__.'/../views/general/error.phtml') ->label('webhook', 'auth.oauth') ->label('scope', 'auth') - // ->label('abuse-limit', 100) - // ->label('abuse-key', 'ip:{ip}') + ->label('abuse-limit', 100) + ->label('abuse-key', 'ip:{ip}') ->label('docs', false) ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider') ->param('code', '', function () { return new Text(1024); }, 'OAuth code') From d6f5d8107367d7a7ce39e55f8ad3eda8f011ae49 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 00:10:27 +0530 Subject: [PATCH 22/50] chore: set abuse-limit to default --- app/controllers/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 17ada8bc3a..e2fd5ab078 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -454,7 +454,7 @@ $utopia->get('/v1/auth/login/oauth/:provider/redirect') ->label('error', __DIR__.'/../views/general/error.phtml') ->label('webhook', 'auth.oauth') ->label('scope', 'auth') - ->label('abuse-limit', 100) + ->label('abuse-limit', 50) ->label('abuse-key', 'ip:{ip}') ->label('docs', false) ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider') From 55707e86cb3310d4a3e2f4033439392391b019a1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 00:11:45 +0530 Subject: [PATCH 23/50] chore: removed abuse-limit in callback endpoint --- app/controllers/auth.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index e2fd5ab078..b038917988 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -435,8 +435,6 @@ $utopia->get('/v1/auth/login/oauth/callback/:provider/:projectId') ->desc('OAuth Callback') ->label('error', __DIR__.'/../views/general/error.phtml') ->label('scope', 'auth') - // ->label('abuse-limit', 100) - // ->label('abuse-key', 'ip:{ip}') ->label('docs', false) ->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID') ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth provider') From ecae436f4f0326401302999763d11fb839600c08 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 00:15:01 +0530 Subject: [PATCH 24/50] chore: removed debug comments --- src/Auth/OAuth/Bitbucket.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index c95d77aeb2..377d9a5142 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -32,13 +32,9 @@ class Bitbucket extends OAuth */ public function getLoginURL(): string { - // add each required scope to the user scopes and pass $this->scopes to the query builder - // var_dump($this->getScopes()); foreach ($this->requiredScope as $item) { $this->addScope($item); } - // var_dump($this->getScopes()); - // exit(); return 'https://bitbucket.org/site/oauth2/authorize?' .http_build_query([ 'response_type' => 'code', From 563ea1363cc6f65efa982329bfe9a7345dcd3768 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 09:57:49 +0530 Subject: [PATCH 25/50] feat: added abuse checks as per review --- app/controllers/auth.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/auth.php b/app/controllers/auth.php index b038917988..253b478470 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -396,8 +396,8 @@ $utopia->get('/v1/auth/login/oauth/:provider') ->label('sdk.description', '/docs/references/auth/login-oauth.md') ->label('sdk.location', true) ->label('sdk.cookies', true) - // ->label('abuse-limit', 100) - // ->label('abuse-key', 'ip:{ip}') + ->label('abuse-limit', 50) + ->label('abuse-key', 'ip:{ip}') ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth Provider. Currently, supported providers are: ' . implode(', ', array_keys($providers))) ->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.') ->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.') From 1f1e4e0def6d46230ed2c792fa7c73efaa0c9ca2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 12:01:36 +0530 Subject: [PATCH 26/50] chore: added duplicate scope check in constructor --- src/Auth/OAuth.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 73ca9a6c10..f60aea9dd9 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -27,7 +27,7 @@ abstract class OAuth /** * @var array */ - protected $userScopes; + protected $scopes; /** * OAuth constructor. @@ -36,15 +36,17 @@ abstract class OAuth * @param string $appSecret * @param string $callback * @param array $state - * @param array $userScopes + * @param array $scopes */ - public function __construct(string $appId, string $appSecret, string $callback, $state = [], $userScopes = []) + public function __construct(string $appId, string $appSecret, string $callback, $state = [], $scopes = []) { $this->appID = $appId; $this->appSecret = $appSecret; $this->callback = $callback; $this->state = $state; - $this->userScopes = $userScopes; + foreach($scopes as $scope) { + $this->addScope($scope); + } } /** @@ -92,8 +94,8 @@ abstract class OAuth */ protected function addScope(string $scope){ // Add a scope to the scopes array if it isn't already present - if (!in_array($scope, $this->userScopes)){ - $this->userScopes[] = $scope; + if (!in_array($scope, $this->scopes)){ + $this->scopes[] = $scope; } } @@ -101,7 +103,7 @@ abstract class OAuth * @return array */ protected function getScopes(){ - return $this->userScopes; + return $this->scopes; } From cda8f27398584157fa9196f4f66378ced86e9676 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 19:42:09 +0530 Subject: [PATCH 27/50] chore: support for chaining in addScope --- src/Auth/OAuth.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index f60aea9dd9..2da7917b91 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -92,11 +92,12 @@ abstract class OAuth * * @return array */ - protected function addScope(string $scope){ + protected function addScope(string $scope):OAuth{ // Add a scope to the scopes array if it isn't already present if (!in_array($scope, $this->scopes)){ $this->scopes[] = $scope; } + return $this; } /** From fe9f79b123697e44b4ccdb1e37c8470f4a1767be Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 19:43:08 +0530 Subject: [PATCH 28/50] chore: corrected function doc --- src/Auth/OAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 2da7917b91..2bfa4e3c00 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -90,7 +90,7 @@ abstract class OAuth /** * @param $scope * - * @return array + * @return $this */ protected function addScope(string $scope):OAuth{ // Add a scope to the scopes array if it isn't already present From b190bc28d843b40fd63d6fb5bad2bdfd1333acbe Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 19:46:41 +0530 Subject: [PATCH 29/50] chore: added required Scopes to Amazon Adapter --- src/Auth/OAuth/Amazon.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index 71bb8aaee6..d249d34214 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -15,6 +15,11 @@ class Amazon extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $requiredScope = []; + /** * @return string */ From 907de3e95f7c8bc916803dd952ccb2e80a31436c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 19:48:47 +0530 Subject: [PATCH 30/50] chore: sanitisation of BitBucket Adapter --- src/Auth/OAuth/Amazon.php | 6 ++++-- src/Auth/OAuth/Bitbucket.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index d249d34214..3e187a5f07 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -18,8 +18,10 @@ class Amazon extends OAuth /** * @var array */ - protected $requiredScope = []; - + protected $requiredScope = [ + "profile" + ]; + /** * @return string */ diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index 377d9a5142..4dd1128cac 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -36,7 +36,7 @@ class Bitbucket extends OAuth $this->addScope($item); } - return 'https://bitbucket.org/site/oauth2/authorize?' .http_build_query([ + return 'https://bitbucket.org/site/oauth2/authorize?'.http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, 'scope' => implode(' ', $this->getScopes()), From 67bda8b9fa508361ce0767b90a227a6b4d70e66d Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 20:02:03 +0530 Subject: [PATCH 31/50] feat: modified Amazon Adapter to use the new custom scopes --- src/Auth/OAuth/Amazon.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index 3e187a5f07..c5dfecb728 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -46,6 +46,10 @@ class Amazon extends OAuth */ public function getLoginURL(): string { + foreach ($this->requiredScope as $item) { + $this->addScope($item); + } + return 'https://www.amazon.com/ap/oa?' . 'client_id='.urlencode($this->appID). '&redirect_uri='.urlencode($this->callback). From 6bc166887775a85144a3f94399a1be2c97b609c0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 13 Jan 2020 20:03:41 +0530 Subject: [PATCH 32/50] chore: Amazon Adapter changes --- src/Auth/OAuth/Amazon.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index c5dfecb728..2694e21fe8 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -49,13 +49,14 @@ class Amazon extends OAuth foreach ($this->requiredScope as $item) { $this->addScope($item); } - - return 'https://www.amazon.com/ap/oa?' . - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&response_type=code'. - '&state='.urlencode(json_encode($this->state)). - '&scope=profile'; + + return 'https://www.amazon.com/ap/oa?'.http_build_query([ + 'response_type' => 'code', + 'client_id' => $this->appID, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state), + 'redirect_uri' => $this->callback + ]); } /** From 9a5b0098a675976f9de3c7e1184f889a4bfa420a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 08:27:02 +0530 Subject: [PATCH 33/50] feat: renamed adapter variable to scope --- src/Auth/OAuth/Bitbucket.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index 4dd1128cac..1b597263be 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -17,7 +17,7 @@ class Bitbucket extends OAuth /** * @var array */ - protected $requiredScope = []; + protected $scope = []; /** * @return string @@ -32,10 +32,6 @@ class Bitbucket extends OAuth */ public function getLoginURL(): string { - foreach ($this->requiredScope as $item) { - $this->addScope($item); - } - return 'https://bitbucket.org/site/oauth2/authorize?'.http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, From 2c937f822168f301dac16eb2eb46924faf3bb031 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 09:06:51 +0530 Subject: [PATCH 34/50] chore: fixed php coding standard --- src/Auth/OAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index 2bfa4e3c00..89dde432f1 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -103,7 +103,7 @@ abstract class OAuth /** * @return array */ - protected function getScopes(){ + protected function getScopes():array{ return $this->scopes; } From a7f0d16596237cfde0dd3f1f1d1fdecba15d7215 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 09:18:47 +0530 Subject: [PATCH 35/50] chore: modified amazon adapter --- src/Auth/OAuth/Amazon.php | 6 +----- src/Auth/OAuth/Bitbucket.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index 2694e21fe8..fd7de98360 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -18,7 +18,7 @@ class Amazon extends OAuth /** * @var array */ - protected $requiredScope = [ + protected $scopes = [ "profile" ]; @@ -46,10 +46,6 @@ class Amazon extends OAuth */ public function getLoginURL(): string { - foreach ($this->requiredScope as $item) { - $this->addScope($item); - } - return 'https://www.amazon.com/ap/oa?'.http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index 1b597263be..c0abb6c5d9 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -17,7 +17,7 @@ class Bitbucket extends OAuth /** * @var array */ - protected $scope = []; + protected $scopes = []; /** * @return string From 1678021ce36f9537609e0ae3b1aa4ce7faa92e78 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 09:49:10 +0530 Subject: [PATCH 36/50] chore: updated Amazon Adapter Methods --- src/Auth/OAuth/Amazon.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Auth/OAuth/Amazon.php b/src/Auth/OAuth/Amazon.php index fd7de98360..64c04fdc90 100644 --- a/src/Auth/OAuth/Amazon.php +++ b/src/Auth/OAuth/Amazon.php @@ -67,11 +67,13 @@ class Amazon extends OAuth 'POST', 'https://api.amazon.com/auth/o2/token', $headers, - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID , + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback , + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From c63eb7fda5ba623718a088af850a2ecbecae1d48 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 10:15:54 +0530 Subject: [PATCH 37/50] chore: Adapter fixes --- src/Auth/OAuth/Apple.php | 20 +++++++++++++------- src/Auth/OAuth/LinkedIn.php | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index fbe4b65b1a..4f626bef9a 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -14,6 +14,11 @@ class Apple extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ["name", "email"]; + /** * @return string */ @@ -27,13 +32,14 @@ class Apple extends OAuth */ public function getLoginURL(): string { - return 'https://appleid.apple.com/auth/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'. - '&response_mode=form_post'. - '&scope=name+email'; + return 'https://appleid.apple.com/auth/authorize?'.http_build_query([ + 'client_id' => urlencode($this->appID), + 'redirect_uri' => urlencode($this->callback), + 'state' => urlencode(json_encode($this->state)), + 'response_type' => 'code', + 'response_mode' => 'form_post', + 'scope' => implode('+', $this->getScopes()) + ]); } /** diff --git a/src/Auth/OAuth/LinkedIn.php b/src/Auth/OAuth/LinkedIn.php index 101e1f09c5..954b9c6ec8 100644 --- a/src/Auth/OAuth/LinkedIn.php +++ b/src/Auth/OAuth/LinkedIn.php @@ -49,7 +49,7 @@ class LinkedIn extends OAuth 'response_type' => 'code', 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'state' => json_encode($this->state), ]); } From f7acaea6a93ec86971f0fc0821a12937b175ce70 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 10:23:41 +0530 Subject: [PATCH 38/50] chore: apple Adapter Fixes --- src/Auth/OAuth/Apple.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index 4f626bef9a..d0abf7be70 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -33,9 +33,9 @@ class Apple extends OAuth public function getLoginURL(): string { return 'https://appleid.apple.com/auth/authorize?'.http_build_query([ - 'client_id' => urlencode($this->appID), - 'redirect_uri' => urlencode($this->callback), - 'state' => urlencode(json_encode($this->state)), + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'state' => json_encode($this->state), 'response_type' => 'code', 'response_mode' => 'form_post', 'scope' => implode('+', $this->getScopes()) @@ -54,11 +54,13 @@ class Apple extends OAuth 'POST', 'https://appleid.apple.com/auth/token', $headers, - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'grant_type' => 'authorization_code' + ]) ); var_dump($accessToken); From 7bd3b7ab469e7ffd5d054bcea51ced3e64540618 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 10:24:40 +0530 Subject: [PATCH 39/50] chore: apple Adapter Fixes --- src/Auth/OAuth/Apple.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index d0abf7be70..c0f7c7274d 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -63,9 +63,6 @@ class Apple extends OAuth ]) ); - var_dump($accessToken); - exit(); - $accessToken = json_decode($accessToken, true); if (isset($accessToken['access_token'])) { From 1e4fe089018c633459ff06ac2266c6ab3121a963 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 18:50:07 +0530 Subject: [PATCH 40/50] chore: updated bitbucket adapter --- src/Auth/OAuth/Bitbucket.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Auth/OAuth/Bitbucket.php b/src/Auth/OAuth/Bitbucket.php index c0abb6c5d9..9e2a86be69 100644 --- a/src/Auth/OAuth/Bitbucket.php +++ b/src/Auth/OAuth/Bitbucket.php @@ -49,15 +49,17 @@ class Bitbucket extends OAuth { // Required as per Bitbucket Spec. $headers[] = 'Content-Type: application/x-www-form-urlencoded'; - + $accessToken = $this->request( 'POST', 'https://bitbucket.org/site/oauth2/access_token', $headers, - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret). - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From 5b5c178b037b31fdfdccd4c54beb17a5b35ce49f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 19:29:35 +0530 Subject: [PATCH 41/50] chore: dropbox adapter changes --- src/Auth/OAuth/Dropbox.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Auth/OAuth/Dropbox.php b/src/Auth/OAuth/Dropbox.php index a4a6335f36..85843718da 100644 --- a/src/Auth/OAuth/Dropbox.php +++ b/src/Auth/OAuth/Dropbox.php @@ -14,6 +14,11 @@ class Dropbox extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = []; + /** * @return string */ @@ -27,11 +32,12 @@ class Dropbox extends OAuth */ public function getLoginURL(): string { - return 'https://www.dropbox.com/oauth2/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'; + return 'https://www.dropbox.com/oauth2/authorize?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'state' => json_encode($this->state), + 'response_type' => 'code' + ]); } /** @@ -46,11 +52,13 @@ class Dropbox extends OAuth 'POST', 'https://api.dropboxapi.com/oauth2/token', $headers, - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From 0ae60726fe7c64a224222783aca4a134a6d285e2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 20:03:39 +0530 Subject: [PATCH 42/50] chore: changes to facebook Adapter --- src/Auth/OAuth/Dropbox.php | 8 ++++---- src/Auth/OAuth/Facebook.php | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Auth/OAuth/Dropbox.php b/src/Auth/OAuth/Dropbox.php index 85843718da..db74215274 100644 --- a/src/Auth/OAuth/Dropbox.php +++ b/src/Auth/OAuth/Dropbox.php @@ -33,10 +33,10 @@ class Dropbox extends OAuth public function getLoginURL(): string { return 'https://www.dropbox.com/oauth2/authorize?'.http_build_query([ - 'client_id' => $this->appID, - 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state), - 'response_type' => 'code' + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'state' => json_encode($this->state), + 'response_type' => 'code' ]); } diff --git a/src/Auth/OAuth/Facebook.php b/src/Auth/OAuth/Facebook.php index ed50748bac..719d6db166 100644 --- a/src/Auth/OAuth/Facebook.php +++ b/src/Auth/OAuth/Facebook.php @@ -16,6 +16,11 @@ class Facebook extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['email']; + /** * @return string */ @@ -29,7 +34,12 @@ class Facebook extends OAuth */ public function getLoginURL():string { - return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state)); + return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.http_build_query([ + 'client_id'=> $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state) + ]); } /** @@ -41,19 +51,20 @@ class Facebook extends OAuth { $accessToken = $this->request( 'GET', - 'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code) + 'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'client_secret' => $this->appSecret, + 'code' => $code + ]) ); - $accessToken = json_decode($accessToken, true); // + $accessToken = json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; } - + return ''; } From 538f5cf1c3f33bafe4ab7f87796ec281bd180d0a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 20:18:11 +0530 Subject: [PATCH 43/50] chore: github adapter changes --- src/Auth/OAuth/GitHub.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Auth/OAuth/GitHub.php b/src/Auth/OAuth/GitHub.php index 405f2f9f78..9eb0ca48f5 100644 --- a/src/Auth/OAuth/GitHub.php +++ b/src/Auth/OAuth/GitHub.php @@ -11,6 +11,11 @@ class Github extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['user:email']; + /** * @return string */ @@ -24,7 +29,13 @@ class Github extends OAuth */ public function getLoginURL():string { - return 'https://github.com/login/oauth/authorize?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=user:email&state='.urlencode(json_encode($this->state)); + return 'https://github.com/login/oauth/authorize?'. http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state) + ]); + } /** @@ -38,10 +49,12 @@ class Github extends OAuth 'POST', 'https://github.com/login/oauth/access_token', [], - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code) + http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'client_secret' => $this->appSecret, + 'code' => $code + ]) ); $output = []; From d2a19207c2469a6d954f3858df0f9e79cbcf4b70 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 20:38:46 +0530 Subject: [PATCH 44/50] chore: gitlab adapter fixes --- src/Auth/OAuth/Gitlab.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php index fbc6df60fa..60f6656797 100644 --- a/src/Auth/OAuth/Gitlab.php +++ b/src/Auth/OAuth/Gitlab.php @@ -14,6 +14,11 @@ class Gitlab extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['read_user']; + /** * @return string */ @@ -27,12 +32,13 @@ class Gitlab extends OAuth */ public function getLoginURL(): string { - return 'https://gitlab.com/oauth/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&scope=read_user'. - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'; + return 'https://gitlab.com/oauth/authorize?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state), + 'response_type' => 'code' + ]); } /** @@ -44,12 +50,13 @@ class Gitlab extends OAuth { $accessToken = $this->request( 'POST', - 'https://gitlab.com/oauth/token?'. - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&grant_type=authorization_code' + 'https://gitlab.com/oauth/token?'.http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From ba96505aa401d136b7e8067e33889ad70abbfb8c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 18 Jan 2020 20:57:48 +0530 Subject: [PATCH 45/50] chore: google oauth adapter changes --- src/Auth/OAuth/Apple.php | 2 +- src/Auth/OAuth/Google.php | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index c0f7c7274d..1157695570 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -38,7 +38,7 @@ class Apple extends OAuth 'state' => json_encode($this->state), 'response_type' => 'code', 'response_mode' => 'form_post', - 'scope' => implode('+', $this->getScopes()) + 'scope' => implode(' ', $this->getScopes()) ]); } diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index 42f4357bd7..28d4072299 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -14,6 +14,12 @@ class Google extends OAuth * @var string */ protected $version = 'v4'; + + /** + * @var array + */ + protected $scopes = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile']; + /** * @var array */ @@ -32,12 +38,13 @@ class Google extends OAuth */ public function getLoginURL(): string { - return 'https://accounts.google.com/o/oauth2/v2/auth?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'. - '&state='.urlencode(json_encode($this->state)). - '&response_type=code'; + return 'https://accounts.google.com/o/oauth2/v2/auth?'. http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state), + 'response_type' => 'code' + ]); } /** @@ -49,13 +56,14 @@ class Google extends OAuth { $accessToken = $this->request( 'POST', - 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'. - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&scope='. - '&grant_type=authorization_code' + 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'.http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'scope' => null, + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From ca6a0e70b642b6dfabf98ef2d156e05303811ae3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:09:37 +0530 Subject: [PATCH 46/50] chore: microsoft adapter changes --- src/Auth/OAuth/LinkedIn.php | 2 +- src/Auth/OAuth/Microsoft.php | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Auth/OAuth/LinkedIn.php b/src/Auth/OAuth/LinkedIn.php index 954b9c6ec8..efe6b6bc86 100644 --- a/src/Auth/OAuth/LinkedIn.php +++ b/src/Auth/OAuth/LinkedIn.php @@ -14,7 +14,7 @@ class LinkedIn extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'r_basicprofile', 'r_emailaddress', ]; diff --git a/src/Auth/OAuth/Microsoft.php b/src/Auth/OAuth/Microsoft.php index 6bbf0bad83..5a465d99b4 100644 --- a/src/Auth/OAuth/Microsoft.php +++ b/src/Auth/OAuth/Microsoft.php @@ -14,6 +14,11 @@ class Microsoft extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['offline_access', 'user.read']; + /** * @return string */ @@ -27,13 +32,14 @@ class Microsoft extends OAuth */ public function getLoginURL(): string { - return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)). - '&scope=offline_access+user.read'. - '&response_type=code'. - '&response_mode=query'; + return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'state'=> json_encode($this->state), + 'scope'=> implode(' ', $this->getScopes()), + 'response_type' => 'code', + 'response_mode' => 'query' + ]); } /** @@ -49,12 +55,14 @@ class Microsoft extends OAuth 'POST', 'https://login.microsoftonline.com/common/oauth2/v2.0/token', $headers, - 'code='.urlencode($code). - '&client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback). - '&scope=offline_access+user.read'. - '&grant_type=authorization_code' + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'grant_type' => 'authorization_code' + ]) ); $accessToken = json_decode($accessToken, true); From efdacd72484a8b84451a6017c2058a34f2aef025 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:14:08 +0530 Subject: [PATCH 47/50] chore: fixed slack adapter --- src/Auth/OAuth/Slack.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Auth/OAuth/Slack.php b/src/Auth/OAuth/Slack.php index 120dd4233d..a9f7dca135 100644 --- a/src/Auth/OAuth/Slack.php +++ b/src/Auth/OAuth/Slack.php @@ -11,6 +11,11 @@ class Slack extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['identity.avatar', 'identity.basic', 'identity.email','identity.team']; + /** * @return string */ @@ -25,11 +30,12 @@ class Slack extends OAuth public function getLoginURL():string { // https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install - return 'https://slack.com/oauth/authorize'. - '?client_id='.urlencode($this->appID). - '&scope=identity.avatar+identity.basic+identity.email+identity.team'. - '&redirect_uri='.urlencode($this->callback). - '&state='.urlencode(json_encode($this->state)); + return 'https://slack.com/oauth/authorize?'.http_build_query([ + 'client_id'=> $this->appID, + 'scope' => implode(' ', $this->getScopes()), + 'redirect_uri' => $this->callback, + 'state' => json_encode($this->state) + ]); } /** @@ -42,11 +48,12 @@ class Slack extends OAuth // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token $accessToken = $this->request( 'GET', - 'https://slack.com/api/oauth.access'. - '?client_id='.urlencode($this->appID). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code). - '&redirect_uri='.urlencode($this->callback) + 'https://slack.com/api/oauth.access?'.http_build_query([ + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'code' => $code, + 'redirect_uri' => $this->callback + ]) ); $accessToken = json_decode($accessToken, true); // @@ -118,7 +125,7 @@ class Slack extends OAuth // https://api.slack.com/methods/users.identity $user = $this->request( 'GET', - 'https://slack.com/api/users.identity?token='.urlencode($accessToken), + 'https://slack.com/api/users.identity?token='.urlencode($accessToken) ); $this->user = json_decode($user, true); From a4630b499569c7c5aa840b28ce85d7078ed5b4f9 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:18:59 +0530 Subject: [PATCH 48/50] chpore: vk adapter changes --- src/Auth/OAuth/Vk.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Auth/OAuth/Vk.php b/src/Auth/OAuth/Vk.php index ad860aff84..2fbc9f9b67 100644 --- a/src/Auth/OAuth/Vk.php +++ b/src/Auth/OAuth/Vk.php @@ -17,6 +17,11 @@ class Vk extends OAuth */ protected $user = []; + /** + * @var array + */ + protected $scopes = ['openid' ,'email']; + /** * @var string */ @@ -36,13 +41,14 @@ class Vk extends OAuth */ public function getLoginURL(): string { - return 'https://oauth.vk.com/authorize?' . - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&response_type=code'. - '&state='.urlencode(json_encode($this->state)). - '&v='.urlencode($this->version). - '&scope=openid+email'; + return 'https://oauth.vk.com/authorize?' . http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'response_type' => 'code', + 'state' => json_encode($this->state), + 'v' => $this->version, + 'scope' => implode(' ', $this->getScopes()) + ]); } /** @@ -57,10 +63,12 @@ class Vk extends OAuth 'POST', 'https://oauth.vk.com/access_token?', $headers, - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret). - '&redirect_uri='.urlencode($this->callback) + http_build_query([ + 'code' => $code, + 'client_id' => $this->appID, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $this->callback + ]) ); $accessToken = json_decode($accessToken, true); From 4d4745ccd29b5a9f9808612318a7709284222ce5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:42:41 +0530 Subject: [PATCH 49/50] chore: refactoring OAuth Adapters --- src/Auth/OAuth/Apple.php | 5 ++++- src/Auth/OAuth/Discord.php | 4 ++-- src/Auth/OAuth/Facebook.php | 4 +++- src/Auth/OAuth/GitHub.php | 4 +++- src/Auth/OAuth/Gitlab.php | 4 +++- src/Auth/OAuth/Google.php | 5 ++++- src/Auth/OAuth/Microsoft.php | 5 ++++- src/Auth/OAuth/Mock.php | 24 +++++++++++++++++++----- src/Auth/OAuth/Slack.php | 7 ++++++- src/Auth/OAuth/Spotify.php | 4 ++-- src/Auth/OAuth/Twitch.php | 4 ++-- src/Auth/OAuth/Vk.php | 14 +++++++++----- src/Auth/OAuth/Yahoo.php | 4 ++-- 13 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/Auth/OAuth/Apple.php b/src/Auth/OAuth/Apple.php index 1157695570..3a5de8ebdc 100644 --- a/src/Auth/OAuth/Apple.php +++ b/src/Auth/OAuth/Apple.php @@ -17,7 +17,10 @@ class Apple extends OAuth /** * @var array */ - protected $scopes = ["name", "email"]; + protected $scopes = [ + "name", + "email" + ]; /** * @return string diff --git a/src/Auth/OAuth/Discord.php b/src/Auth/OAuth/Discord.php index b23653e992..54cf5546b6 100644 --- a/src/Auth/OAuth/Discord.php +++ b/src/Auth/OAuth/Discord.php @@ -20,7 +20,7 @@ class Discord extends OAuth protected $user = []; - protected $scope = [ + protected $scopes = [ 'identify', 'email' ]; @@ -42,7 +42,7 @@ class Discord extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback ]); diff --git a/src/Auth/OAuth/Facebook.php b/src/Auth/OAuth/Facebook.php index 719d6db166..c3c348e493 100644 --- a/src/Auth/OAuth/Facebook.php +++ b/src/Auth/OAuth/Facebook.php @@ -19,7 +19,9 @@ class Facebook extends OAuth /** * @var array */ - protected $scopes = ['email']; + protected $scopes = [ + 'email' + ]; /** * @return string diff --git a/src/Auth/OAuth/GitHub.php b/src/Auth/OAuth/GitHub.php index 9eb0ca48f5..e0e056930d 100644 --- a/src/Auth/OAuth/GitHub.php +++ b/src/Auth/OAuth/GitHub.php @@ -14,7 +14,9 @@ class Github extends OAuth /** * @var array */ - protected $scopes = ['user:email']; + protected $scopes = [ + 'user:email' + ]; /** * @return string diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php index 60f6656797..d74e97a766 100644 --- a/src/Auth/OAuth/Gitlab.php +++ b/src/Auth/OAuth/Gitlab.php @@ -17,7 +17,9 @@ class Gitlab extends OAuth /** * @var array */ - protected $scopes = ['read_user']; + protected $scopes = [ + 'read_user' + ]; /** * @return string diff --git a/src/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index 28d4072299..cad8c537d8 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -18,7 +18,10 @@ class Google extends OAuth /** * @var array */ - protected $scopes = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile']; + protected $scopes = [ + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile' + ]; /** * @var array diff --git a/src/Auth/OAuth/Microsoft.php b/src/Auth/OAuth/Microsoft.php index 5a465d99b4..c2c99a38d7 100644 --- a/src/Auth/OAuth/Microsoft.php +++ b/src/Auth/OAuth/Microsoft.php @@ -17,7 +17,10 @@ class Microsoft extends OAuth /** * @var array */ - protected $scopes = ['offline_access', 'user.read']; + protected $scopes = [ + 'offline_access', + 'user.read' + ]; /** * @return string diff --git a/src/Auth/OAuth/Mock.php b/src/Auth/OAuth/Mock.php index 004836e0e9..4c99ee6404 100644 --- a/src/Auth/OAuth/Mock.php +++ b/src/Auth/OAuth/Mock.php @@ -11,6 +11,13 @@ class Mock extends OAuth */ protected $version = 'v1'; + /** + * @var array + */ + protected $scopes = [ + 'email' + ]; + /** * @var array */ @@ -29,7 +36,12 @@ class Mock extends OAuth */ public function getLoginURL():string { - return 'http://localhost/'.$this->version.'/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state)); + return 'http://localhost/'.$this->version.'/oauth?'. http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'scope' => implode(' ', $this->getScopes()), + 'state' => json_encode($this->state) + ]); } /** @@ -42,10 +54,12 @@ class Mock extends OAuth $accessToken = $this->request( 'GET', 'http://localhost/'.$this->version.'/oauth/token?'. - 'client_id='.urlencode($this->appID). - '&redirect_uri='.urlencode($this->callback). - '&client_secret='.urlencode($this->appSecret). - '&code='.urlencode($code) + http_build_query([ + 'client_id' => $this->appID, + 'redirect_uri' => $this->callback, + 'client_secret' => $this->appSecret, + 'code' => $code + ]) ); $accessToken = json_decode($accessToken, true); // diff --git a/src/Auth/OAuth/Slack.php b/src/Auth/OAuth/Slack.php index a9f7dca135..3458e743b6 100644 --- a/src/Auth/OAuth/Slack.php +++ b/src/Auth/OAuth/Slack.php @@ -14,7 +14,12 @@ class Slack extends OAuth /** * @var array */ - protected $scopes = ['identity.avatar', 'identity.basic', 'identity.email','identity.team']; + protected $scopes = [ + 'identity.avatar', + 'identity.basic', + 'identity.email', + 'identity.team' + ]; /** * @return string diff --git a/src/Auth/OAuth/Spotify.php b/src/Auth/OAuth/Spotify.php index 84cd9d0151..92c366026f 100644 --- a/src/Auth/OAuth/Spotify.php +++ b/src/Auth/OAuth/Spotify.php @@ -23,7 +23,7 @@ class Spotify extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'user-read-email', ]; @@ -49,7 +49,7 @@ class Spotify extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'state' => json_encode($this->state) ]); diff --git a/src/Auth/OAuth/Twitch.php b/src/Auth/OAuth/Twitch.php index b9455bd58a..e5ecb5b142 100644 --- a/src/Auth/OAuth/Twitch.php +++ b/src/Auth/OAuth/Twitch.php @@ -23,7 +23,7 @@ class Twitch extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'user:read:email', ]; @@ -49,7 +49,7 @@ class Twitch extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'force_verify' => true, 'state' => json_encode($this->state) diff --git a/src/Auth/OAuth/Vk.php b/src/Auth/OAuth/Vk.php index 2fbc9f9b67..1878fbd348 100644 --- a/src/Auth/OAuth/Vk.php +++ b/src/Auth/OAuth/Vk.php @@ -20,7 +20,10 @@ class Vk extends OAuth /** * @var array */ - protected $scopes = ['openid' ,'email']; + protected $scopes = [ + 'openid', + 'email' + ]; /** * @var string @@ -144,10 +147,11 @@ class Vk extends OAuth if (empty($this->user['name'])) { $user = $this->request( 'GET', - 'https://api.vk.com/method/users.get?'. - 'v='.urlencode($this->version). - '&fields=id,name,email,first_name,last_name'. - '&access_token='.urlencode($accessToken) + 'https://api.vk.com/method/users.get?'. http_build_query([ + 'v' => $this->version, + 'fields' => 'id,name,email,first_name,last_name', + 'access_token' => $accessToken + ]) ); $user = json_decode($user, true); diff --git a/src/Auth/OAuth/Yahoo.php b/src/Auth/OAuth/Yahoo.php index c14e4c6650..84aa596684 100644 --- a/src/Auth/OAuth/Yahoo.php +++ b/src/Auth/OAuth/Yahoo.php @@ -23,7 +23,7 @@ class Yahoo extends OAuth /** * @var array */ - protected $scope = [ + protected $scopes = [ 'sdct-r', 'sdpp-w', ]; @@ -61,7 +61,7 @@ class Yahoo extends OAuth http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->scope), + 'scope' => implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'state' => json_encode($this->state) ]); From ed983b4f3477accdb307bc4e6b25a8e2039287e0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 19 Jan 2020 01:44:38 +0530 Subject: [PATCH 50/50] chore: updated providers list --- app/config/providers.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/config/providers.php b/app/config/providers.php index 0c42972e86..5dc43e8e56 100644 --- a/app/config/providers.php +++ b/app/config/providers.php @@ -109,16 +109,17 @@ return [ 'enabled' => true, 'mock' => false, ], + 'twitter' => [ + 'developers' => 'https://developer.twitter.com/', + 'icon' => 'icon-twitter', + 'enabled' => false, + 'mock' => false + ], // Keep Last 'mock' => [ 'developers' => 'https://appwrite.io', 'icon' => 'icon-appwrite', 'enabled' => true, 'mock' => true, - ], - 'twitter' => [ - 'developers' => 'https://developer.twitter.com/', - 'icon' => 'icon-twitter', - 'enabled' => false, ] ];