Skip to content

Commit

Permalink
Merge pull request #13 from randyzwitch/cleanup-0.6
Browse files Browse the repository at this point in the history
Update for 0.6
  • Loading branch information
randyzwitch authored Aug 13, 2017
2 parents ae7b516 + e2c6e96 commit 626fa80
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OAuth

Travis-CI: [![Build Status](https://travis-ci.org/randyzwitch/OAuth.jl.svg?branch=master)](https://travis-ci.org/randyzwitch/OAuth.jl) <br>
OSX/Linux: [![Build Status](https://travis-ci.org/randyzwitch/OAuth.jl.svg?branch=master)](https://travis-ci.org/randyzwitch/OAuth.jl) <br>
Windows:
[![Build status](https://ci.appveyor.com/api/projects/status/lu2jwu1yh464bdm4/branch/master?svg=true)](https://ci.appveyor.com/project/randyzwitch/oauth-jl/branch/master)
<br>
Coveralls: [![codecov.io](https://codecov.io/github/randyzwitch/OAuth.jl/coverage.svg?branch=master)](https://codecov.io/github/randyzwitch/OAuth.jl?branch=master)

My interpretation of the OAuth 1.0 protocol, based on my reading of [RFC5849](https://tools.ietf.org/html/rfc5849), the [liboauth](http://liboauth.sourceforge.net/) C library and factoring out the OAuth authentication code from [Twitter.jl](https://github.com/randyzwitch/Twitter.jl). At one point, this package relied on liboauth and was a wrapper of that library's functions built using [Clang.jl](https://github.com/ihnorton/Clang.jl); however, as I cleaned up the auto-generated functions from Clang, I decided that it would be easier and cleaner to re-write the library in Julia rather than require liboauth.
Expand Down
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
julia 0.6
Compat
FactCheck
Nettle 0.2
Requests
Expand Down
33 changes: 33 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"OAuth\"); Pkg.build(\"OAuth\")"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"OAuth\")"
25 changes: 12 additions & 13 deletions src/OAuth.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
VERSION >= v"0.4" && __precompile__()
__precompile__()

module OAuth

using Compat
using URIParser, Requests, Nettle

export
Expand Down Expand Up @@ -33,22 +32,22 @@ function oauth_timestamp()
end

#Generate random string
function oauth_nonce(length::Int64)
function oauth_nonce(length::Int)
randstring(length)
end

#HMAC-SHA1 sign message
function oauth_sign_hmac_sha1(message::AbstractString,signingkey::AbstractString)
function oauth_sign_hmac_sha1(message::String,signingkey::String)
base64encode(digest("sha1", signingkey, message))
end

#Create signing key
function oauth_signing_key(oauth_consumer_secret::AbstractString, oauth_token_secret::AbstractString)
function oauth_signing_key(oauth_consumer_secret::String, oauth_token_secret::String)
"$(oauth_consumer_secret)&$(oauth_token_secret)"
end

#Create signature_base_string
function oauth_signature_base_string(httpmethod::AbstractString, url::AbstractString, parameterstring::AbstractString)
function oauth_signature_base_string(httpmethod::String, url::String, parameterstring::String)
"$(httpmethod)&$(encodeURI(url))&$(encodeURI(parameterstring))"
end

Expand Down Expand Up @@ -86,7 +85,7 @@ encodeURI(s) = URIParser.escape(s)

function encodeURI!(dict_of_parameters::Dict)
for (k, v) in dict_of_parameters
if typeof(v) <: AbstractString
if typeof(v) <: String
dict_of_parameters[k] = encodeURI(v)
end
end
Expand All @@ -98,15 +97,15 @@ end
encodeURI!(dict_of_parameters::Dict)
)

function oauth_body_hash_file(filename::AbstractString)
oauth_body_hash_data(readall(open(filename)))
function oauth_body_hash_file(filename::String)
oauth_body_hash_data(readstring(open(filename)))
end

function oauth_body_hash_data(data::AbstractString)
function oauth_body_hash_data(data::String)
"oauth_body_hash=$(oauth_body_hash_encode(data))"
end

function oauth_body_hash_encode(data::AbstractString)
function oauth_body_hash_encode(data::String)
base64encode(digest("SHA1", data))
end

Expand Down Expand Up @@ -143,15 +142,15 @@ function oauth_header(httpmethod, baseurl, options, oauth_consumer_key, oauth_co

end

function oauth_request_resource(endpoint::AbstractString, httpmethod::AbstractString, options::Dict, oauth_consumer_key::AbstractString, oauth_consumer_secret::AbstractString, oauth_token::AbstractString, oauth_token_secret::AbstractString)
function oauth_request_resource(endpoint::String, httpmethod::String, options::Dict, oauth_consumer_key::String, oauth_consumer_secret::String, oauth_token::String, oauth_token_secret::String)
#Build query string
query_str = Requests.format_query_str(options)

#Build oauth_header
oauth_header_val = oauth_header(httpmethod, endpoint, options, oauth_consumer_key, oauth_consumer_secret, oauth_token, oauth_token_secret)

#Make request
headers = Dict{AbstractString,AbstractString}(
headers = Dict{String,String}(
"Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => oauth_header_val,
"Accept" => "*/*"
Expand Down

0 comments on commit 626fa80

Please sign in to comment.