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
相关文章推荐
- yesod / yesod-auth / openid
- yesod / yesod-auth / browserid
- yesod / yesod-auth / Yesod / Auth
- Yesod - 类型类 (5)
- Haskell的yesod框架-1
- Yesod - 路由和响应 (6)
- Haskell的Yesod技术大全
- [OAuth]基于DotNetOpenAuth实现Client Credentials Grant
- Yesod - 数据库 (9)
- Yesod is a Haskell web framework
- 基于DotNetOpenAuth的OAuth实现示例代码: 获取access token
- Yesod - Haskell (1)
- yesod / yesod-auth / auth2
- Yesod - 基础结构 (2)
- Yesod - 组件 (4)
- yesod / yesod-core / widget-benchmark
- 用DotNetOpenAuth实现基于OAuth 2.0的web api授权 (一)Getting Start
- Yesod - 简介 (0)
- Could not load file or assembly 'DotNetOpenAuth.OAuth.Consumer'
- 土豆网(第三方网站)使用qq登录的步骤和原理------oAuth协议