-
Notifications
You must be signed in to change notification settings - Fork 29
/
OAuth.hs
89 lines (74 loc) · 3.09 KB
/
OAuth.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{- hpodder component
Copyright (C) 2010 John Goerzen <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
{- |
Module : OAuth
Copyright : Copyright (C) 2010 John Goerzen
License : GNU GPL, version 2 or above
Maintainer : John Goerzen <[email protected]>
Stability : provisional
Portability: portable
Written by John Goerzen, jgoerzen\@complete.org
-}
module OAuth where
import Network.OAuth.Consumer
import Data.Maybe
import Network.OAuth.Http.Request
import Network.OAuth.Http.HttpClient
import Data.ConfigFile
import Utils
import Data.Either.Utils
obfuscatedTwitterKeys = ("jRlf9pXnU7uEV5ZcxrJmc",
"L17bXFykkLYz4TBCmet1wuX9VtXbLq8Xj4Lif42O4ew")
identicaKeys = ("f027d666f9d0e7b80beaed528aec473c",
"d84c9b3dafb14becb5e05a002886b60c")
twitterKeys = (twitterDeObfuscator (fst obfuscatedTwitterKeys),
twitterDeObfuscator (snd obfuscatedTwitterKeys))
twitterDeObfuscator :: String -> String
twitterDeObfuscator = reverse . map rot13
instance Show Application where
show (Application a b c) = "Application " ++ show a ++ " " ++ show b ++ " " ++ show c
instance Show Token where
show (TwoLegg app oauthp) = "TwoLegg " ++ show app ++ " " ++ show oauthp
show (ReqToken app oauthp) = "ReqToken " ++ show app ++ " " ++ show oauthp
show (AccessToken app oauthp) = "AccessToken " ++ show app ++ " " ++ show oauthp
rot13 :: Char -> Char
rot13 x =
case lookup x trans of
Just y -> y
Nothing -> x
where trans = zip (lcbase ++ ucbase) (part lcbase ++ part ucbase)
lcbase = ['a' .. 'z']
ucbase = ['A' .. 'Z']
part x = drop 13 x ++ take 13 x
getDefaultKeys :: ConfigParser -> Maybe (String, String)
getDefaultKeys cp =
case serverHost cp of
"api.twitter.com" -> Just twitterKeys
"twitter.com" -> Just twitterKeys
"identi.ca" -> Just identicaKeys
getApp :: ConfigParser -> Maybe Application
getApp cp =
if (has_option cp "DEFAULT" "oauthconsumerkey" &&
has_option cp "DEFAULT" "oauthconsumersecret")
then Just $ Application
{consKey =
forceEither $ get cp "DEFAULT" "oauthconsumerkey",
consSec =
forceEither $ get cp "DEFAULT" "oauthconsumersecret",
callback = OOB}
else case getDefaultKeys cp of
Just (k, s) -> Just $ Application {consKey = k, consSec = s,
callback = OOB}
Nothing -> Nothing