forked from shkh/lastfm-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
66 lines (57 loc) · 1.65 KB
/
auth.go
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
package lastfm
import (
"net/url"
)
//Mobile app style
func (api *Api) Login(username, password string) (err error) {
defer func() { appendCaller(err, "lastfm.Login") }()
var result AuthGetMobileSession
args := P{"username": username, "password": password}
if err = callPostWithoutSession("auth.getmobilesession", api.params, args, &result, P{
"plain": []string{"username", "password"},
}); err != nil {
return
}
api.params.sk = result.Key
//api.creds.username = result.Name
return
}
//Desktop app style
func (api Api) GetToken() (token string, err error) {
defer func() { appendCaller(err, "lastfm.GetToken") }()
var result AuthGetToken
if err = callGet("auth.gettoken", api.params, nil, &result, P{}); err != nil {
return
}
token = result.Token
return
}
func (api Api) GetAuthTokenUrl(token string) (uri string) {
urlParams := url.Values{}
urlParams.Add("api_key", api.params.apikey)
urlParams.Add("token", token)
uri = constructUrl(UriBrowserBase, urlParams)
return
}
//Web app style
func (api Api) GetAuthRequestUrl(callback string) (uri string) {
urlParams := url.Values{}
urlParams.Add("api_key", api.params.apikey)
if callback != "" {
urlParams.Add("cb", callback)
}
uri = constructUrl(UriBrowserBase, urlParams)
return
}
//Desktop and Web app style
func (api *Api) LoginWithToken(token string) (err error) {
defer func() { appendCaller(err, "lastfm.LoginWithToken") }()
var result AuthGetSession
args := P{"token": token}
if err = callPostWithoutSession("auth.getsession", api.params, args, &result, P{"plain": []string{"token"}}); err != nil {
return
}
api.params.sk = result.Key
//api.params.username = result.Name
return
}