You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/09/07 02:40:45 UTC

[incubator-ponymail-foal] branch master updated (8e49dbe -> c46652b)

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git.


    from 8e49dbe  If private emails within search results, adjust years according to AAA
     new 6ab968c  add oauth config section
     new 88c5e22  Set data if passed, add oauth_data sub-object
     new a94db38  Add very generic OAuth plugin
     new 71fec70  strip header key
     new c46652b  Add OAuth endpoint

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 server/endpoints/oauth.py       | 66 +++++++++++++++++++++++++++++++++++++++++
 server/plugins/configuration.py |  8 +++++
 server/plugins/oauthGeneric.py  | 18 +++++++++++
 server/plugins/session.py       | 12 ++++++--
 4 files changed, 102 insertions(+), 2 deletions(-)
 create mode 100644 server/endpoints/oauth.py
 create mode 100644 server/plugins/oauthGeneric.py


[incubator-ponymail-foal] 02/05: Set data if passed, add oauth_data sub-object

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 88c5e2282d5830fcc427bde334d581f08513e42e
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 7 04:30:01 2020 +0200

    Set data if passed, add oauth_data sub-object
---
 server/plugins/session.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/server/plugins/session.py b/server/plugins/session.py
index 9f6c4d3..fde3cfc 100644
--- a/server/plugins/session.py
+++ b/server/plugins/session.py
@@ -37,10 +37,17 @@ class SessionCredentials:
     provider: str
     authoritative: bool
     admin: bool
+    oauth_data: dict
 
     def __init__(self, doc: typing.Dict = None):
         if doc:
-            pass
+            self.uid = doc.get('uid', '')
+            self.name = doc.get('name', '')
+            self.email = doc.get('email', '')
+            self.provider = doc.get('provider', 'generic')
+            self.authoritative = doc.get('authoritative', False)
+            self.admin = doc.get('admin', False)
+            self.oauth_data = doc.get('oauth_data', {})
         else:
             self.uid = ""
             self.name = ""
@@ -48,6 +55,7 @@ class SessionCredentials:
             self.provider = "generic"
             self.authoritative = False
             self.admin = False
+            self.oauth_data = {}
 
 
 class SessionObject:


[incubator-ponymail-foal] 03/05: Add very generic OAuth plugin

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit a94db38b1d18efd1f832b8d07751a5ec3bf74057
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 7 04:30:22 2020 +0200

    Add very generic OAuth plugin
---
 server/plugins/oauthGeneric.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/server/plugins/oauthGeneric.py b/server/plugins/oauthGeneric.py
new file mode 100644
index 0000000..e3eb57b
--- /dev/null
+++ b/server/plugins/oauthGeneric.py
@@ -0,0 +1,18 @@
+# Generic OAuth plugin
+import re
+import requests
+
+
+def process(formdata, session):
+    js = None
+    m = re.match(r"https?://(.+)/", formdata["oauth_token"])
+    if m:
+        oauth_domain = m.group(1)
+        headers = {"User-Agent": "Pony Mail OAuth Agent/0.1"}
+        rv = requests.post(formdata["oauth_token"], headers=headers, data=formdata)
+        # try:
+        js = rv.json()
+        js["oauth_domain"] = oauth_domain
+        js['authoritative'] = True
+
+    return js


[incubator-ponymail-foal] 05/05: Add OAuth endpoint

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit c46652b4bfc0b488404e5b9cf1d8a17c837ff462
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 7 04:38:36 2020 +0200

    Add OAuth endpoint
---
 server/endpoints/oauth.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/server/endpoints/oauth.py b/server/endpoints/oauth.py
new file mode 100644
index 0000000..b6d06c0
--- /dev/null
+++ b/server/endpoints/oauth.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Parent OAuth endpoint for Pony Mail codename Foal"""
+
+import plugins.server
+import plugins.session
+import plugins.oauthGeneric
+import typing
+import aiohttp.web
+
+
+async def process(
+    server: plugins.server.BaseServer,
+    session: plugins.session.SessionObject,
+    indata: dict,
+) -> typing.Union[dict, aiohttp.web.Response]:
+
+    state = indata.get("state")
+    code = indata.get("code")
+    oauth_token = indata.get("oauth_token")
+
+    # Generic OAuth handler, only one we support for now. Works with ASF OAuth.
+    if state and code and oauth_token:
+        rv: typing.Optional[dict] = plugins.oauthGeneric.process(indata, session)
+        if rv:
+            # Get UID, fall back to using email address
+            uid = rv.get("uid")
+            if not uid:
+                uid = rv.get("email")
+            if uid:
+                cookie = await plugins.session.set_session(
+                    server,
+                    uid=uid,
+                    name=rv.get("name"),
+                    email=rv.get("email"),
+                    # Authoritative if OAuth domain is in the authoritative oauth section in ponymail.yaml
+                    # Required for access to private emails
+                    authoritative=rv.get('oauth_domain', 'generic') in server.config.oauth.authoritative_domains,
+                    oauth_data=rv,
+                )
+                # This could be improved upon, instead of a raw response return value
+                return aiohttp.web.Response(
+                    headers={
+                        'set-cookie': cookie,
+                        'content-type': 'application/json'
+                    }, status=200, text='{"okay": true}'
+                )
+
+
+def register(server: plugins.server.BaseServer):
+    return plugins.server.Endpoint(process)


[incubator-ponymail-foal] 01/05: add oauth config section

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 6ab968c32f069ecec0d71305d25c1cd5c008861d
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 7 04:29:18 2020 +0200

    add oauth config section
---
 server/plugins/configuration.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/server/plugins/configuration.py b/server/plugins/configuration.py
index 65e5db4..a622fdf 100644
--- a/server/plugins/configuration.py
+++ b/server/plugins/configuration.py
@@ -14,6 +14,12 @@ class TaskConfig:
         self.refresh_rate = int(subyaml.get("refresh_rate", 150))
 
 
+class OAuthConfig:
+    authoritative_domains: list
+
+    def __init__(self, subyaml: dict):
+        self.authoritative_domains = subyaml.get('authoritative_domains', [])
+
 class DBConfig:
     hostname: str
     port: int
@@ -35,11 +41,13 @@ class Configuration:
     server: ServerConfig
     database: DBConfig
     tasks: TaskConfig
+    oauth: OAuthConfig
 
     def __init__(self, yml: dict):
         self.server = ServerConfig(yml.get("server", {}))
         self.database = DBConfig(yml.get("database", {}))
         self.tasks = TaskConfig(yml.get("tasks", {}))
+        self.oauth = OAuthConfig(yml.get("oauth", {}))
 
 
 class InterData:


Re: [incubator-ponymail-foal] 04/05: strip header key

Posted by Daniel Gruno <hu...@apache.org>.
On 07/09/2020 13.36, sebb wrote:
> On Mon, 7 Sep 2020 at 03:40, <hu...@apache.org> wrote:
>>
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> humbedooh pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
>>
>> commit 71fec7052798634d9556b225530e0cfdbc788d57
>> Author: Daniel Gruno <hu...@apache.org>
>> AuthorDate: Mon Sep 7 04:38:21 2020 +0200
>>
>>      strip header key
>> ---
>>   server/plugins/session.py | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/server/plugins/session.py b/server/plugins/session.py
>> index fde3cfc..bd5abff 100644
>> --- a/server/plugins/session.py
>> +++ b/server/plugins/session.py
>> @@ -115,5 +115,5 @@ async def set_session(server: plugins.server.BaseServer, **credentials):
>>       session = SessionObject(server)
>>       session.credentials = SessionCredentials(credentials)
>>       server.data.sessions[session_id] = session
>> +    return cookie.output(header='').lstrip()
> 
> Why is that lstrip() and not strip()?

It's a work in progress. The output function will always return a full 
HTTP response header line, which is something like "Set-Cookie: foo". If 
you specify no header, it will still print out " foo" instead of "foo", 
so we strip the left side of it for whitespace. I'm looking into a way 
to just get the value and not have any header key inserted.

> 
>>
>> -    return cookie.output()
>>


Re: [incubator-ponymail-foal] 04/05: strip header key

Posted by sebb <se...@gmail.com>.
On Mon, 7 Sep 2020 at 03:40, <hu...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> humbedooh pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
>
> commit 71fec7052798634d9556b225530e0cfdbc788d57
> Author: Daniel Gruno <hu...@apache.org>
> AuthorDate: Mon Sep 7 04:38:21 2020 +0200
>
>     strip header key
> ---
>  server/plugins/session.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/server/plugins/session.py b/server/plugins/session.py
> index fde3cfc..bd5abff 100644
> --- a/server/plugins/session.py
> +++ b/server/plugins/session.py
> @@ -115,5 +115,5 @@ async def set_session(server: plugins.server.BaseServer, **credentials):
>      session = SessionObject(server)
>      session.credentials = SessionCredentials(credentials)
>      server.data.sessions[session_id] = session
> +    return cookie.output(header='').lstrip()

Why is that lstrip() and not strip()?

>
> -    return cookie.output()
>

[incubator-ponymail-foal] 04/05: strip header key

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 71fec7052798634d9556b225530e0cfdbc788d57
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 7 04:38:21 2020 +0200

    strip header key
---
 server/plugins/session.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/plugins/session.py b/server/plugins/session.py
index fde3cfc..bd5abff 100644
--- a/server/plugins/session.py
+++ b/server/plugins/session.py
@@ -115,5 +115,5 @@ async def set_session(server: plugins.server.BaseServer, **credentials):
     session = SessionObject(server)
     session.credentials = SessionCredentials(credentials)
     server.data.sessions[session_id] = session
+    return cookie.output(header='').lstrip()
 
-    return cookie.output()