From 77def611ccec2469f353f6c3af14b6658a752d5f Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 5 Sep 2021 00:47:44 +0000 Subject: [PATCH] Add Discourse auth --- apiserver/apiserver/api/serializers.py | 34 +++++++++++++++---- apiserver/apiserver/api/utils_auth.py | 12 +++++++ apiserver/apiserver/secrets.py.example | 5 +++ webclient/public/discourselogo.png | Bin 0 -> 3049 bytes webclient/public/wikilogo.png | Bin 1090 -> 5869 bytes webclient/src/Auth.js | 43 ++++++++++++++++++++++--- 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 webclient/public/discourselogo.png diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index c769574..c4f857e 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -561,11 +561,20 @@ class MyPasswordChangeSerializer(PasswordChangeSerializer): data = dict( username=self.user.username, password=self.data['new_password1'], + email=self.user.email, + first_name=self.user.member.first_name, ) if utils_auth.wiki_is_configured(): if utils_auth.set_wiki_password(data) != 200: - msg = 'Problem connecting to Auth server: set.' + msg = 'Problem connecting to Wiki Auth server: set.' + utils.alert_tanner(msg) + logger.info(msg) + raise ValidationError(dict(non_field_errors=msg)) + + if utils_auth.discourse_is_configured(): + if utils_auth.set_discourse_password(data) != 200: + msg = 'Problem connecting to Discourse Auth server: set.' utils.alert_tanner(msg) logger.info(msg) raise ValidationError(dict(non_field_errors=msg)) @@ -602,11 +611,20 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): data = dict( username=self.user.username, password=self.data['new_password1'], + email=self.user.email, + first_name=self.user.member.first_name, ) if utils_auth.wiki_is_configured(): if utils_auth.set_wiki_password(data) != 200: - msg = 'Problem connecting to Auth server: set.' + msg = 'Problem connecting to Wiki Auth server: set.' + utils.alert_tanner(msg) + logger.info(msg) + raise ValidationError(dict(non_field_errors=msg)) + + if utils_auth.discourse_is_configured(): + if utils_auth.set_discourse_password(data) != 200: + msg = 'Problem connecting to Discourse Auth server: set.' utils.alert_tanner(msg) logger.info(msg) raise ValidationError(dict(non_field_errors=msg)) @@ -653,10 +671,14 @@ class HistorySerializer(serializers.ModelSerializer): class SpaceportAuthSerializer(LoginSerializer): def authenticate(self, **kwargs): - result = super().authenticate(**kwargs) + user = super().authenticate(**kwargs) + + if user: + data = self.context['request'].data.copy() + data['email'] = user.email + data['first_name'] = user.member.first_name - if result: - data = self.context['request'].data utils_auth.set_wiki_password(data) + utils_auth.set_discourse_password(data) - return result + return user diff --git a/apiserver/apiserver/api/utils_auth.py b/apiserver/apiserver/api/utils_auth.py index 6a6f1a2..98481ec 100644 --- a/apiserver/apiserver/api/utils_auth.py +++ b/apiserver/apiserver/api/utils_auth.py @@ -9,6 +9,9 @@ from apiserver.api import utils def wiki_is_configured(): return bool(secrets.WIKI_AUTH_API_URL and secrets.AUTH_API_KEY) +def discourse_is_configured(): + return bool(secrets.DISCOURSE_AUTH_API_URL and secrets.AUTH_API_KEY) + def auth_api(url, data): try: @@ -25,3 +28,12 @@ def set_wiki_password(data): password=data['password'], ) return auth_api(secrets.WIKI_AUTH_API_URL + 'set-wiki-password', auth_data) + +def set_discourse_password(data): + auth_data = dict( + username=data['username'], + password=data['password'], + first_name=data['first_name'], + email=data['email'], + ) + return auth_api(secrets.DISCOURSE_AUTH_API_URL + 'set-discourse-password', auth_data) diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 1cf694e..0827e23 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -45,6 +45,11 @@ LDAP_API_KEY = '' # with trailing slash WIKI_AUTH_API_URL = '' +# Discourse Auth API url +# should contain the IP and port of the script and machine connected over VPN +# with trailing slash +DISCOURSE_AUTH_API_URL = '' + # Auth API key # should be equal to the auth token value set in # spaceport/authserver/secrets.py diff --git a/webclient/public/discourselogo.png b/webclient/public/discourselogo.png new file mode 100644 index 0000000000000000000000000000000000000000..294285f3765f7395db2359e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eS|r+@jhiuUQyCDbve}gb&r<| z?v#O^EW@2nhY{TYF(9TPxuOXuk_triBS$|f>CSn-gaADm=J4^c{W$D2#L-ECwgvq( zZd5lw-SB~loL_)(BA=cCW8M1m8Rk zfj5pJs(s`X4%5RUD^63ps$mcG{J@+)jsWm&Fjy>@RD<0?-Z*M$PRRX0^8OHe*1p-) zuIk^v`>!`71jMs7+~9R|0+;3-y$*={+2xWihRD214EEN)@OO*1orrd{8!Xsk)gSw zdlN7FeE>bELU2;hF@!`^!@GfbP|Lo7iSzWkRaJbKx$kIskM;JbKuZ4&)Nq>n@P(g6 zCHp|zo9s75CH{)ie*-n_J4KFN_&HR678Eo)B^?R5zlI^Dm&fs~|b` z>{p`_0986F>bp_>_b5<2jO|-diQAg;lh}SWD)GbCwA5*F-+@Yq8@8fpnZwL-JrwGe zi*VnX^`}rrcr+NjB`O{ZP%4rVQaZw{7;4#*6SbVXm{Zl?6BTNOTA@~`6>5cAp;o9B rYK2;%R;U$fg<7Fjs1<63`rG0^{p$(Ow^|1x00000NkvXXu0mjf(bMBl literal 0 HcmV?d00001 diff --git a/webclient/public/wikilogo.png b/webclient/public/wikilogo.png index 228f35244c652adbd5cc8d179e3a47a6f8c57bdd..e0763eeee3362dd8f6b0bc3ca8511e74bdf4c8ac 100644 GIT binary patch literal 5869 zcmbtYhd)*CAAjtTajnd_W`l^3S=YXm5!u;$@4d1z!$lDZg)6!CjudXX%7}1@bdBs0 zvg7>jw}0VxUe7t_v)=E|`}I7}>vf*jNxrA6MNi8`3jm|KoJ#9k`Eg$U@O$sOnoL(ne(Pk+V<$&S=6b_&e0A&Ek7(hk<3i!{h66AwY{tF)S zQ$XebvI39|fT95O0zh5>N(Mv{NE|?-{~)>miUm+HfbIYY0U!+k=>v!ubOg{t02Td1 zl>kT%K*|7m2B6yjGWkd71E72WWdleGKo0X*RS2{?WMCSv6p zVAuuJ7lGh5pxp;7@Iw1c8aMT0279jl=NHqhQ4j@HDbpx?MAXEbs zi2Th!wh(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%+r?Tt)?2%BN2-_W!NDzQSt z_X*g!T*&$aM4mFMVz3olbooFd%_UsMU@teEV5;uYGk5}=A27a#QpYhT1~)>lzLvz3w%{Z;6|ixF5-E3 z6ySzf(#}QsLw^okIno}as5Z`tAvTxFNdI { if (input.username.includes('@')) { - setError({ username: 'Username, not email.' }); + setError({ username: 'Spaceport username, not email.' }); } else { if (loading) return; setLoading(true); @@ -104,12 +104,43 @@ export function AuthWiki(props) {

would like to request Spaceport authentication.

-

URL: wiki.protospace.ca

+

URL: wiki.protospace.ca

Success!
-

You can now log into the wiki:

-

Protospace Wiki

+

You can now log into the Wiki:

+

+ Username: {user.username}
+ Password: [this Spaceport password] +

+

Protospace Wiki

+
+ + ); +} + +export function AuthDiscourse(props) { + const { user } = props; + + return ( + +
+ + Protospace Discourse +
+ +

would like to request Spaceport authentication.

+ +

URL: forum.protospace.ca

+ + +
Success!
+

You can now log into the Discourse:

+

+ Username: {user.username}
+ Password: [this Spaceport password] +

+

Protospace Discourse

); @@ -127,6 +158,10 @@ export function Auth(props) { + + + + ); }