Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
84916a9c
Commit
84916a9c
authored
8 years ago
by
echicken
Browse files
Options
Downloads
Patches
Plain Diff
Basic OAuth1 client for making signed get/post requests; only tested against Twitter so far.
parent
485b9981
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/oauth.js
+104
-0
104 additions, 0 deletions
exec/load/oauth.js
with
104 additions
and
0 deletions
exec/load/oauth.js
0 → 100644
+
104
−
0
View file @
84916a9c
load
(
'
hmac.js
'
);
load
(
'
http.js
'
);
function
_encodeURIComponent
(
str
)
{
return
encodeURIComponent
(
str
).
replace
(
/
[
!'()*
]
/g
,
function
(
c
)
{
return
'
%
'
+
c
.
charCodeAt
(
0
).
toString
(
16
);
}
);
}
function
generate_nonce
(
l
)
{
var
s
=
''
;
var
c
=
'
0123456789ABCDEFabcdef
'
.
split
(
''
);
for
(
var
n
=
0
;
n
<
l
;
n
++
)
s
+=
c
[
Math
.
floor
(
Math
.
random
()
*
c
.
length
)];
return
s
;
}
function
merge_objects
()
{
var
o
=
{};
Array
.
prototype
.
slice
.
call
(
arguments
).
forEach
(
function
(
e
)
{
Object
.
keys
(
e
).
forEach
(
function
(
f
)
{
o
[
f
]
=
e
[
f
];
});
}
);
return
o
;
}
function
param_stringify
(
params
,
quote
,
delim
)
{
return
Object
.
keys
(
params
).
map
(
function
(
e
)
{
return
(
_encodeURIComponent
(
e
)
+
'
=
'
+
(
quote
?
'
"
'
:
''
)
+
_encodeURIComponent
(
params
[
e
])
+
(
quote
?
'
"
'
:
''
)
);
}
).
sort
().
join
(
delim
);
}
var
OAuth1_Client
=
function
()
{
function
build_oauth_params
(
consumer_key
,
token
)
{
var
obj
=
{
oauth_consumer_key
:
consumer_key
,
oauth_nonce
:
generate_nonce
(
32
),
oauth_signature_method
:
'
HMAC-SHA1
'
,
oauth_timestamp
:
time
()
+
''
,
oauth_version
:
'
1.0
'
};
if
(
token
)
obj
.
oauth_token
=
token
;
return
obj
;
}
function
get_base_string
(
method
,
url
,
params
,
data
)
{
if
(
data
)
params
=
merge_objects
(
params
,
data
);
return
(
_encodeURIComponent
(
method
)
+
'
&
'
+
_encodeURIComponent
(
url
)
+
'
&
'
+
_encodeURIComponent
(
param_stringify
(
params
,
false
,
'
&
'
))
);
}
function
get_signature
(
base_string
,
consumer_secret
,
token_secret
)
{
return
base64_encode
(
hmac_sha1
(
_encodeURIComponent
(
consumer_secret
)
+
'
&
'
+
(
token_secret
?
_encodeURIComponent
(
token_secret
)
:
''
),
base_string
)
);
}
this
.
get
=
function
(
url
,
key
,
secret
,
token
,
token_secret
)
{
url
=
url
.
split
(
'
?
'
);
var
_url
=
url
.
shift
();
var
data
=
{};
if
(
url
.
length
>
0
)
{
url
.
join
(
'
?
'
).
split
(
'
&
'
).
forEach
(
function
(
e
)
{
e
=
e
.
split
(
'
=
'
);
if
(
e
.
length
<
2
)
return
;
data
[
e
][
0
]
=
data
[
e
][
1
];
}
);
}
var
params
=
build_oauth_params
(
key
,
token
);
var
base_string
=
get_base_string
(
'
GET
'
,
_url
,
params
,
data
);
params
.
oauth_signature
=
get_signature
(
base_string
,
secret
,
token_secret
);
return
(
new
HTTPRequest
(
false
,
false
,
{
Authorization
:
'
OAuth
'
+
param_stringify
(
params
,
true
,
'
,
'
)
}
)).
Get
(
_url
+
'
?
'
+
param_stringify
(
data
,
false
,
'
&
'
));
}
this
.
post
=
function
(
url
,
data
,
key
,
secret
,
token
,
token_secret
)
{
var
params
=
build_oauth_params
(
key
,
token
);
var
base_string
=
get_base_string
(
'
POST
'
,
url
,
params
,
data
);
params
.
oauth_signature
=
get_signature
(
base_string
,
secret
,
token_secret
);
return
(
new
HTTPRequest
(
false
,
false
,
{
Authorization
:
'
OAuth
'
+
param_stringify
(
params
,
true
,
'
,
'
)
}
)).
Post
(
url
,
param_stringify
(
data
,
false
,
'
&
'
));
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment