Changes between Version 8 and Version 9 of login-service


Ignore:
Timestamp:
Jun 1, 2016, 11:23:20 AM (4 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • login-service

    v8 v9  
    11= Login Service =
    22
    3 May First/People Link provides a web-based API for verifying login credentials called "login-service". It is designed to allow applications to verify that a given username and password is valid. It takes as input a username, password, and application id, and responds with either a 1 (indicating invalid) or a 0 indicating a valid username and password.
     3May First/People Link provides a web-based API for verifying login credentials called "login-service". It is designed to allow applications to verify that a given username and password is valid or that a given username exists.
     4
     5In "check" mode it takes as input a username, password, and application id, and responds with either a no (indicating invalid) or a yes indicating a valid username and password or error.
     6
     7In "user" mode it takes as input a username and application id, and responds with either a no (indicating the username doesn't exist) or a yes indicating a valid username or error.
    48
    59== Server side ==
     
    2024{{{
    2125#!/bin/bash
    22 user="$1"
    23 pass="$2"
    24 app_id="$3"
    25 out=$(curl -s "https://id.mayfirst.org:8080/check?user=$user&password=$pass&app_id=$3")
     26
     27service="$1"
     28app_id="$2"
     29user="$3"
     30pass="$4"
     31
     32if [ -z "$service" -o -z "$app_id" -o -z "$user" ]; then
     33  printf "Please pass service app_id and user as the first three arguments.\n"
     34  exit 2
     35fi
     36
     37if [ "$service" != "user" -a "$service" != "check" ]; then
     38  printf "Service must be user or check.\n"
     39  exit 2
     40fi
     41
     42if [ "$service" = "check" -a -z "$pass" ]; then
     43  printf "If you pass user as the service, the last argument should be a password.\n"
     44  exit 2
     45fi
     46
     47out=$(curl -s "https://id.mayfirst.org:8080/${service}?user=${user}&password=${pass}&app_id=${app_id}")
     48
    2649[ "$out" = "yes" ] && exit 0
    2750exit 1
     
    4164username = 'YOUR-USER-NAME'
    4265password = 'YOUR-PASSWORD'
     66appid = 'YOUR-APP-ID'
    4367
    44 check = auth(username, password)
     68check = auth(username, password, appid)
    4569
    4670if check == "0":
     
    5983
    6084# set the login service URL
    61 url = 'https://id.mayfirst.org:8080/check'
    62 # this python lib uses a standard id
    63 appid= 'THESTRINGOFTHEAPPID'
     85url = 'https://id.mayfirst.org:8080/'
    6486
    6587
    66 def auth(username, password):
     88def auth(username, password, appid):
    6789    values = {'user' : username,
    6890              'password' : password,
    6991              'app_id' : appid}
    7092   
    71     req = requests.post(url, data=values)
     93    req = requests.post(url + "check", data=values)
     94    is_valid_user = req.text
     95
     96    if is_valid_user == "yes":
     97        return "0"
     98    return "1"
     99
     100def user(username):
     101    values = {'user' : username,
     102              'app_id' : appid}
     103   
     104    req = requests.post(url + user, data=values)
    72105    is_valid_user = req.text
    73106