updated readmes

This commit is contained in:
ronnyabraham 2020-03-02 22:20:34 +02:00
parent 6bc06589ef
commit e51571951d
5 changed files with 153 additions and 1 deletions

View file

@ -17,6 +17,10 @@
[ubuntu community postgres docs](https://help.ubuntu.com/community/PostgreSQL)
#### certbot
[certbot webpage to install ssl certificates](https://certbot.eff.org)
## adding/deleting users
@ -183,6 +187,7 @@ AWS has a sudo group that allows a user sudo priveleges
sudo apt-get update
sudo apt-get install aptitude
## postgres
@ -275,11 +280,40 @@ add the following:
echo ". /usr/local/bin/virtualenvwrapper.sh" >> .bashrc
### install nginx
## nginx
sudo apt-get install nginx
## certbot
In order to use ssl/https it is necessary to install a certificate. This is especially true if the nginx config file has *already* been set up to use ssl. (for example, you are reinstalling an environment, or creating production based on staging, etc)
[certbot.eff.org](certbot.eff.org) allows you to install a free certificate
#### add certbot ppa
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
#### install certbot
sudo apt-get install certbot python-certbot-nginx
#### Choose how you'd like to run certbot
##### OPTION1: get and install your certificates
sudo apt-get install certbot python-certbot-nginx
##### OPTION2: just get the certificate (already configured)
sudo certbot --nginx
Use Option1 when you are just starting a project, but you know you are going to be using SSL
Use Option2 when you have already set up nginx to work with https, for example, you are reinstalling an existing project, etc.
# bootstrap server
fab (prod|rel) deploy.bootstrap

View file

@ -0,0 +1,46 @@
## Multiple header values
when you have more than one header value, ie you want to pass the authentication token **and** you want to pass json values
simply state each header value separately while preceeding it with the -H/--header prefix
e.g.
`-H "Authentication: Bearer 2342343" \`
`-H "Content-Type: application/json" `
note the forward slash \ is used to separate between lines for readability
## Passing the Authentication token
get an authentication token from the server
then pass it in through the header
`--header "Authorization: Bearer <token>`
## Passing Json Values Through Curl
##### step 1 - set the header
`--header "Content-Type: application/json"`
##### step 2 - encode the values
`-d "{\"name\":\"$2\", \"code\":\"$3\"}"`
the bracketed area must be enclose with double quotes (single could work, but we need to change the parameters into strings, and bash does not seem to do that with singles)
the parameter names and values must also be enclosed in **backslashed** double quotes
`\"`
this means the entire string has to be enclosed in normal doubles instead of singles to interpolate the values
## various
[how can i set the request header for curl](https://stackoverflow.com/questions/4212503/how-can-i-set-the-request-header-for-curl/45313572)
[curl snippets](https://gist.github.com/subfuzion/08c5d85437d5d4f00e58)
###### interpolate
*insert (something of a different nature) into something else.*

View file

@ -0,0 +1,23 @@
## Notes
facebook authorization requests are different than straight user/pass requests. One requires the user and pass registered with the django app when they signed in, etc. The other is via the users facebook account.
So the user must paas in his facebook account name and password
### try using standard api get token method
Unlike the facebook request,this one passes the username and password that is already stored in Django
http http://127.0.0.1:8026/api-token-auth/ username=someuser1 password=testpass1
got to [facebook dev apps](https://developers.facebook.com/apps/)
get the
facebook test user name/pass
get client id and client secret from settings
apply:
`curl -X POST -d "client_id=<client_id>&client_secret=<client_secret>&grant_type=password&username=<user_name>&password=<password>" http://localhost:8000/auth/token

View file

@ -0,0 +1,17 @@
## how to set up postgis
use [docker-postgis](https://github.com/kartoza/docker-postgis)
#### setting docker-postgis to use django unit testing
1. get into the running docker shell
2. open postgresql client as postgres user (you have to do this from the command line in the container as you cannot do it remotely)
3. ALTER ROLE \<user_name\> SUPERUSER;
4. set \<user_name> as admin
now the admin can run the tests
`sudo docker exec -it minyanfinder_development_db bash`

View file

@ -0,0 +1,32 @@
in order to use the facebook login with our DRF we need to first get an access token from facebook
then we must login to an OAuth2 application to get an authorization token from our system
so we must have an OAuth Application set up before we can use the facebook token with the DRF
1. install [Django OAuth Toolkit](https://django-oauth-toolkit.readthedocs.io/en/latest/)
2. read and apply [Step 3: Register an application](https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html#step-3-register-an-application)
note: step 2 can be done in the admin under Django OAuth Toolkit > Application
1. install the [Django rest-framework Social OAuth2](https://github.com/RealmTeam/django-rest-framework-social-oauth2) package
2. go to the facebook developers [debug access token](https://developers.facebook.com/tools/accesstoken/) page, and get a fake user access token
3. test it using the shell script *facebook_convert.sh* which is located in **/opt/shell-commands/social_rest**
4. or just run the command
`curl -X POST -d "grant_type=convert_token`
`&client_id=$CLIENT_ID`
`&client_secret=$CLIENT_SECRET`
`&backend=facebook`
`&token=$FACEBOOK_USER_TOKEN"`
` $baseurl/auth/convert-token`
where CLIENT\_ID, CLIENT\_SECRET, AND FACEBOOK\_USER\_TOKEN are all either variables or direct values put in the proper places
CLIENT\_ID and CLIENT_SECRET you get from the OAuth application you created before. That application manages authorized user tokens to let users make DRF requests on authorization only parts of the system
FACEBOOK\_USER\_TOKEN is a value you get **AFTER** you've logged into facebook. at the facebook developers [debug access token page](https://developers.facebook.com/tools/accesstoken/) you look up the Facebook app you are trying to log into, and get a debug user access token.
In production, this means that you ahve to log into facebook **only** via web or by ios, you **absolutely cannot** log into facebook by the command line. No way.
So in production you will have to retrieve the access token facebook provides after login, *then* make the call to retrieve *yet another* access token from the Django OAuth Application you set up on your web server.