您的位置:首页 > 其它

yesod / yesod-auth-oauth

2012-03-19 11:29 204 查看

oauthUrl::Text->AuthRoute

oauthUrlname=PluginRname["forward"]


authOAuth::YesodAuthm

=>OAuth--^'OAuth'data-typeforsigning.

->(Credential->IO(Credsm))--^Howtoextractident.

->AuthPluginm

authOAuthoauthmkCreds=AuthPluginnamedispatchlogin

where

name=T.pack$oauthServerNameoauth

url=PluginRname[]

lookupTokenSecret=bsToText.fromMaybe"".lookup"oauth_token_secret".unCredential

oauthSessionName="__oauth_token_secret"

dispatch"GET"["forward"]=do

render<-getUrlRender

tm<-getRouteToMaster

letoauth'=oauth{oauthCallback=Just$encodeUtf8$render$tmurl}

master<-getYesod

tok<-lift$getTemporaryCredentialoauth'(authHttpManagermaster)

setSessionoauthSessionName$lookupTokenSecrettok

redirect$authorizeUrloauth'tok

dispatch"GET"[]=do

reqTok<-

ifoauthVersionoauth==OAuth10

thendo

oaTok<-runInputGet$ireqtextField"oauth_token"

tokSec<-fromJust<$>lookupSessionoauthSessionName

deleteSessionoauthSessionName

return$Credential[("oauth_token",encodeUtf8oaTok)

,("oauth_token_secret",encodeUtf8tokSec)

]

elsedo

(verifier,oaTok)<-

runInputGet$(,)<$>ireqtextField"oauth_verifier"

<*>ireqtextField"oauth_token"

tokSec<-fromJust<$>lookupSessionoauthSessionName

deleteSessionoauthSessionName

return$Credential[("oauth_verifier",encodeUtf8verifier)

,("oauth_token",encodeUtf8oaTok)

,("oauth_token_secret",encodeUtf8tokSec)

]

master<-getYesod

accTok<-lift$getAccessTokenoauthreqTok(authHttpManagermaster)

creds<-resourceLiftBase$mkCredsaccTok

setCredsTruecreds

dispatch__=notFound

logintm=do

render<-liftgetUrlRender

letoaUrl=render$tm$oauthUrlname

addHtml

[QQ(shamlet)|<ahref=#{oaUrl}>Loginvia#{name}|]


authTwitter::YesodAuthm

=>ByteString--^ConsumerKey

->ByteString--^ConsumerSecret

->AuthPluginm

authTwitterkeysecret=authOAuth

(newOAuth{oauthServerName="twitter"

,oauthRequestUri="https://api.twitter.com/oauth/request_token"

,oauthAccessTokenUri="https://api.twitter.com/oauth/access_token"

,oauthAuthorizeUri="https://api.twitter.com/oauth/authorize"

,oauthSignatureMethod=HMACSHA1

,oauthConsumerKey=key

,oauthConsumerSecret=secret

,oauthVersion=OAuth10a

})

extractCreds

where

extractCreds(Credentialdic)=do

letcrId=decodeUtf8WithlenientDecode$fromJust$lookup"screen_name"dic

return$Creds"twitter"crId$map(bsToText***bsToText)dic


twitterUrl::AuthRoute

twitterUrl=oauthUrl"twitter"


authTumblr::YesodAuthm

=>ByteString--^ConsumerKey

->ByteString--^ConsumerSecret

->AuthPluginm

authTumblrkeysecret=authOAuth

(newOAuth{oauthServerName="tumblr"

,oauthRequestUri="http://www.tumblr.com/oauth/request_token"

,oauthAccessTokenUri="http://www.tumblr.com/oauth/access_token"

,oauthAuthorizeUri="http://www.tumblr.com/oauth/authorize"

,oauthSignatureMethod=HMACSHA1

,oauthConsumerKey=key

,oauthConsumerSecret=secret

,oauthVersion=OAuth10a

})

extractCreds

where

extractCreds(Credentialdic)=do

letcrId=decodeUtf8WithlenientDecode$fromJust$lookup"name"dic

return$Creds"tumblr"crId$map(bsToText***bsToText)dic


tumblrUrl::AuthRoute

tumblrUrl=oauthUrl"tumblr"


bsToText::ByteString->Text

bsToText=decodeUtf8WithlenientDecode
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: