Skip to content

Instantly share code, notes, and snippets.

@mikepea
Last active September 24, 2018 18:21
Show Gist options
  • Save mikepea/bae41ac657866bb10e849bf3078a7fd6 to your computer and use it in GitHub Desktop.
Save mikepea/bae41ac657866bb10e849bf3078a7fd6 to your computer and use it in GitHub Desktop.

Revisions

  1. mikepea revised this gist Jun 15, 2016. 1 changed file with 15 additions and 9 deletions.
    24 changes: 15 additions & 9 deletions curl_oauth2_weekdone.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,18 @@
    You'll need to register an 'app' with Weekdone, as per their API docs.

    CLIENT_ID={provided by weekdone app registration}
    CLIENT_SECRET={provided by weekdone app registration}
    REDIRECT_URL=https://localhost # this does not need to be valid, we just use it to snag the auth code
    USER=[email protected]
    PASSWORD=your_password_here

    # presents a login form :/
    curl -v 'https://weekdone.com/oauth_authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&response_type=code'

    # gives 302 redirect to oauth_authorize
    Login, to get a session cookie

    curl -v -X POST -d "email=$USER" -d "password=$PASSWORD" https://weekdone.com/login
    #< Set-Cookie: ln=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; expires=Sat, 10-Sep-2016 23:42:32 GMT; path=/

    Then using this cookie, connect to the oauth_authorize endpoint to get the auth code.

    # gives 302 redirect to https://localhost/code=xxxx
    curl -v --cookie 'ln=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' "https://weekdone.com/oauth_authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&response_type=code"

    @@ -19,16 +21,20 @@
    # ... and just pulling it out of the broken localhost redirect that comes back after you login
    #

    # Use auth-code to get token
    Use auth-code to get token & refresh token

    curl -v -X POST -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URL}&code=${AUTH_CODE}&grant_type=authorization_code" https://weekdone.com/oauth_token
    AUTH_TOKEN={returned_by_above}
    REFRESH_TOKEN={returned_by_above}

    # Now start using the API!
    Now start using the API!

    # Add an item (type_id=1 == Done, type_id=2 == In Progress)
    curl -X POST -d "type_id=1&description=woo-api" https://api.weekdone.com/1/item?token=${AUTH_TOKEN}

    # List your own items:
    # List your own items
    curl https://api.weekdone.com/1/items?user_id=me&token=${AUTH_TOKEN} | jq -C '.' | less -r

    Token will expire, you can refresh it:

    # Refresh expired token:
    curl -v -X POST -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URL}&code=${AUTH_CODE}&grant_type=refresh_token&refresh_token=${REFRESH_TOKEN}" https://weekdone.com/oauth_token
    curl -v -X POST -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URL}&code=${AUTH_CODE}&grant_type=refresh_token&refresh_token=${REFRESH_TOKEN}" https://weekdone.com/oauth_token
  2. mikepea created this gist Jun 15, 2016.
    34 changes: 34 additions & 0 deletions curl_oauth2_weekdone.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    CLIENT_ID={provided by weekdone app registration}
    CLIENT_SECRET={provided by weekdone app registration}
    REDIRECT_URL=https://localhost # this does not need to be valid, we just use it to snag the auth code
    [email protected]
    PASSWORD=your_password_here

    # presents a login form :/
    curl -v 'https://weekdone.com/oauth_authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&response_type=code'

    # gives 302 redirect to oauth_authorize
    curl -v -X POST -d "email=$USER" -d "password=$PASSWORD" https://weekdone.com/login
    #< Set-Cookie: ln=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; expires=Sat, 10-Sep-2016 23:42:32 GMT; path=/

    # gives 302 redirect to https://localhost/code=xxxx
    curl -v --cookie 'ln=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' "https://weekdone.com/oauth_authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&response_type=code"

    # it's also possible to get this auth code by browsing to:
    # https://weekdone.com/oauth_authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URL}&response_type=code
    # ... and just pulling it out of the broken localhost redirect that comes back after you login
    #

    # Use auth-code to get token
    curl -v -X POST -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URL}&code=${AUTH_CODE}&grant_type=authorization_code" https://weekdone.com/oauth_token
    AUTH_TOKEN={returned_by_above}
    REFRESH_TOKEN={returned_by_above}

    # Now start using the API!
    curl -X POST -d "type_id=1&description=woo-api" https://api.weekdone.com/1/item?token=${AUTH_TOKEN}

    # List your own items:
    curl https://api.weekdone.com/1/items?user_id=me&token=${AUTH_TOKEN} | jq -C '.' | less -r

    # Refresh expired token:
    curl -v -X POST -d "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=${REDIRECT_URL}&code=${AUTH_CODE}&grant_type=refresh_token&refresh_token=${REFRESH_TOKEN}" https://weekdone.com/oauth_token