Skip to content

Commit

Permalink
remapping auth endpoints in dedicated .env file for distant auth
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienParis committed Jun 17, 2019
1 parent 1cd68bf commit 581f74f
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 24 deletions.
8 changes: 8 additions & 0 deletions appserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,21 @@ def app_runner(mode, docker, host, port, mongodb, auth_mode, rsa, anojwt, antisp
else :
env_path_mailing = Path('.') / 'example.env.mailing'

# if auth_mode != 'internal' :
# env_path_auth = Path('.') / '.env.auth'
# else :
env_path_auth = Path('.') / 'example.env.auth'

else :
env_path_global = Path('.') / '.env.global'
env_path_mongodb = Path('.') / '.env.mongodb'
env_path_mailing = Path('.') / '.env.mailing'
env_path_auth = Path('.') / '.env.auth'

load_dotenv(env_path_global, verbose=True)
load_dotenv(env_path_mongodb, verbose=True)
load_dotenv(env_path_mailing, verbose=True)
load_dotenv(env_path_auth, verbose=True)



Expand All @@ -141,6 +148,7 @@ def app_runner(mode, docker, host, port, mongodb, auth_mode, rsa, anojwt, antisp
run_mode=mode,
docker_mode=docker,
mongodb_mode=mongodb,

auth_mode=auth_mode,

RSA_mode=rsa,
Expand Down
128 changes: 128 additions & 0 deletions example.env.auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
### - - - - - - - - - - - - - - ###
### AUTH URL ROOTS
### - - - - - - - - - - - - - - ###

AUTH_URL_ROOT_LOCAL=http://localhost:4100/api/
AUTH_URL_ROOT_DISTANT_PROD=https://toktok-auth.com/api/
AUTH_URL_ROOT_DISTANT_PREPOD=https://preprod.toktok-auth.com/api/



### - - - - - - - - - - - - - - ###
### USERS LIST RELATED
### - - - - - - - - - - - - - - ###

AUTH_DISTANT_USER_GET_ONE=usr/infos/get_one/
AUTH_DISTANT_USER_GET_ONE_METHOD=GET
AUTH_DISTANT_USER_GET_ONE_URL_ARGS=token:access_token
AUTH_DISTANT_USER_GET_ONE_POST_ARGS=none
AUTH_DISTANT_USER_GET_ONE_URL_APPEND=doc_id

AUTH_DISTANT_USER_GET_LIST=usr/infos/list
AUTH_DISTANT_USER_GET_LIST_METHOD=GET
AUTH_DISTANT_USER_GET_LIST_URL_ARGS=token:access_token,key_2:val_key
AUTH_DISTANT_USER_GET_LIST_POST_ARGS=none
AUTH_DISTANT_USER_GET_LIST_URL_APPEND=none



### - - - - - - - - - - - - - - ###
### ONE USER RELATED
### - - - - - - - - - - - - - - ###

AUTH_DISTANT_USER_REGISTER=usr/register
AUTH_DISTANT_USER_REGISTER_METHOD=POST
AUTH_DISTANT_USER_REGISTER_URL_ARGS=token:ano_token
AUTH_DISTANT_USER_REGISTER_POST_ARGS=name:name,surname:surname,email:email,pwd:pwd,lang:lang,agreement:agreement
AUTH_DISTANT_USER_REGISTER_URL_APPEND=none

AUTH_DISTANT_USER_CONF_EMAIL=usr/register/confirm_email
AUTH_DISTANT_USER_CONF_EMAIL_METHOD=GET
AUTH_DISTANT_USER_CONF_EMAIL_URL_ARGS=token:access_token
AUTH_DISTANT_USER_CONF_EMAIL_POST_ARGS=none
AUTH_DISTANT_USER_CONF_EMAIL_URL_APPEND=none

AUTH_DISTANT_USER_EDIT=usr/edit/
AUTH_DISTANT_USER_EDIT_METHOD=PUT
AUTH_DISTANT_USER_EDIT_URL_ARGS=token:access_token
AUTH_DISTANT_USER_EDIT_POST_ARGS=edit_auth:edit_auth,doc_type:doc_type,add_to_list:add_to_list,field_to_update:field_to_update,field_value:field_value
AUTH_DISTANT_USER_EDIT_URL_APPEND=usr_id

AUTH_DISTANT_USER_DELETE=usr/edit/
AUTH_DISTANT_USER_DELETE_METHOD=DELETE
AUTH_DISTANT_USER_DELETE_URL_ARGS=token:access_token
AUTH_DISTANT_USER_DELETE_POST_ARGS=usr_id:usr_id
AUTH_DISTANT_USER_DELETE_URL_APPEND=usr_id



### - - - - - - - - - - - - - - ###
### LOGIN RELATED
### - - - - - - - - - - - - - - ###

AUTH_DISTANT_USER_LOGIN=auth/login/
AUTH_DISTANT_USER_LOGIN_METHOD=POST
AUTH_DISTANT_USER_LOGIN_URL_ARGS=token:ano_token
AUTH_DISTANT_USER_LOGIN_POST_ARGS=email:email,pwd:pwd
AUTH_DISTANT_USER_LOGIN_URL_APPEND=none

AUTH_DISTANT_USER_LOGIN_ANO=auth/login/anonymous/
AUTH_DISTANT_USER_LOGIN_ANO_METHOD=GET
AUTH_DISTANT_USER_LOGIN_ANO_URL_ARGS=none
AUTH_DISTANT_USER_LOGIN_ANO_POST_ARGS=none
AUTH_DISTANT_USER_LOGIN_ANO_URL_APPEND=none



### - - - - - - - - - - - - - - ###
### TOKENS RELATED
### - - - - - - - - - - - - - - ###

AUTH_DISTANT_USER_TOK_CONFIRM=auth/tokens/confirm_access
AUTH_DISTANT_USER_TOK_CONFIRM_METHOD=GET
AUTH_DISTANT_USER_TOK_CONFIRM_URL_ARGS=token:access_token
AUTH_DISTANT_USER_TOK_CONFIRM_POST_ARGS=none
AUTH_DISTANT_USER_TOK_CONFIRM_URL_APPEND=none

AUTH_DISTANT_USER_TOK_FRESH=auth/tokens/fresh_access_token
AUTH_DISTANT_USER_TOK_FRESH_METHOD=GET
AUTH_DISTANT_USER_TOK_FRESH_URL_ARGS=token:refresh_token
AUTH_DISTANT_USER_TOK_FRESH_POST_ARGS=none
AUTH_DISTANT_USER_TOK_FRESH_URL_APPEND=none

AUTH_DISTANT_USER_TOK_NEW=auth/tokens/new_access_token
AUTH_DISTANT_USER_TOK_NEW_METHOD=GET
AUTH_DISTANT_USER_TOK_NEW_URL_ARGS=token:access_token
AUTH_DISTANT_USER_TOK_NEW_POST_ARGS=none
AUTH_DISTANT_USER_TOK_NEW_URL_APPEND=none

AUTH_DISTANT_USER_TOK_NEW_REFRESH=auth/tokens/new_refresh_token/
AUTH_DISTANT_USER_TOK_NEW_REFRESH_METHOD=POST
AUTH_DISTANT_USER_TOK_NEW_REFRESH_URL_ARGS=none
AUTH_DISTANT_USER_TOK_NEW_REFRESH_POST_ARGS=none
AUTH_DISTANT_USER_TOK_NEW_REFRESH_URL_APPEND=old_refresh_token



### - - - - - - - - - - - - - - ###
### PASSWORD RELATED
### - - - - - - - - - - - - - - ###

AUTH_DISTANT_PWD_FORGOT=auth/password/password_forgotten
AUTH_DISTANT_PWD_FORGOT_METHOD=POST
AUTH_DISTANT_PWD_FORGOT_URL_ARGS=token:ano_token
AUTH_DISTANT_PWD_FORGOT_POST_ARGS=email:email
AUTH_DISTANT_PWD_FORGOT_URL_APPEND=none

AUTH_DISTANT_PWD_RESET=auth/password/reset_password
AUTH_DISTANT_PWD_RESET_METHOD=POST
AUTH_DISTANT_PWD_RESET_URL_ARGS=token:access_token
AUTH_DISTANT_PWD_RESET_POST_ARGS=old_pwd:old_pwd,new_pwd:new_pwd
AUTH_DISTANT_PWD_RESET_URL_APPEND=none

AUTH_DISTANT_PWD_RESET_LINK=auth/password/reset_password
AUTH_DISTANT_PWD_RESET_LINK_METHOD=GET
AUTH_DISTANT_PWD_RESET_LINK_URL_ARGS=renew_pwd_access_token:renew_pwd_access_token
AUTH_DISTANT_PWD_RESET_LINK_POST_ARGS=none
AUTH_DISTANT_PWD_RESET_LINK_URL_APPEND=none

6 changes: 3 additions & 3 deletions example.env.global
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ MONGODB_MODE=local
# choose between : interrnal | local | distant_prod | distant_preprod
AUTH_MODE=local

AUTH_URL_ROOT_LOCAL=http://localhost:4100/
AUTH_URL_ROOT_DISTANT_PROD=https://toktok-auth.com/
AUTH_URL_ROOT_DISTANT_PREPOD=https://preprod.toktok-auth.com/
# AUTH_URL_ROOT_LOCAL=http://localhost:4100/
# AUTH_URL_ROOT_DISTANT_PROD=https://toktok-auth.com/
# AUTH_URL_ROOT_DISTANT_PREPOD=https://preprod.toktok-auth.com/

RSA_MODE=yes
ANOJWT_MODE=yes
Expand Down
25 changes: 17 additions & 8 deletions solidata_api/_auth/auth_distant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
from flask import request, current_app as app, jsonify

def getDistantAuthUrl():

auth_mode = app.config["AUTH_MODE"]
log.debug("getDistantAuthUrl / auth_mode : %s", auth_mode )

auth_url_root_modes = {
"local" : app.config["AUTH_URL_ROOT_LOCAL"],
"distant_prod" : app.config["AUTH_URL_ROOT_DISTANT_PROD"],
"distant_preprod" : app.config["AUTH_URL_ROOT_DISTANT_PREPOD"],
}
if auth_mode != 'internal' :

auth_url_root_modes = {
"local" : app.config["AUTH_URL_ROOT_LOCAL"],
"distant_prod" : app.config["AUTH_URL_ROOT_DISTANT_PROD"],
"distant_preprod" : app.config["AUTH_URL_ROOT_DISTANT_PREPOD"],
}

auth_url_root = auth_url_root_modes[auth_mode]
log.debug("getDistantAuthUrl / auth_url_root : %s", auth_url_root )
auth_url_root = auth_url_root_modes[auth_mode]
log.debug("getDistantAuthUrl / auth_url_root : %s", auth_url_root )

return auth_url_root
return auth_url_root

else :
return False


def checkJWT(token, token_type, return_resp=False):
Expand Down Expand Up @@ -52,6 +58,9 @@ def distant_auth (func_name=None, as_decorator=True) :
log.debug("-@- distant_auth ... func_name : %s", func_name)
computed = "test distannt_auth not as decorator"

auth_url_root = getDistantAuthUrl()
log.debug("-@- distant_auth / auth_url_root : %s", auth_url_root )

def _distant_auth(func):
"""
"""
Expand Down
Loading

0 comments on commit 581f74f

Please sign in to comment.