-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathauthentication.go
61 lines (53 loc) · 2.35 KB
/
authentication.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
package tmdb
import (
"fmt"
)
// AuthenticationToken struct
type AuthenticationToken struct {
Success bool
RequestToken string `json:"request_token"`
ExpiresAt string `json:"expires_at,omitempty"`
}
// AuthenticationSession struct
type AuthenticationSession struct {
Success bool
SessionID string `json:"session_id"`
}
// AuthenticationGuestSession struct
type AuthenticationGuestSession struct {
Success bool
GuestSessionID string `json:"guest_session_id"`
ExpiresAt string `json:"expires_at"`
}
// GetAuthToken generates a valid request token for user based authentication
// https://developers.themoviedb.org/3/authentication/create-request-token
func (tmdb *TMDb) GetAuthToken() (*AuthenticationToken, error) {
var token AuthenticationToken
uri := fmt.Sprintf("%s/authentication/token/new?api_key=%s", baseURL, tmdb.apiKey)
result, err := getTmdb(uri, &token)
return result.(*AuthenticationToken), err
}
// GetAuthValidateToken authenticates a user with a TMDb username and password
// https://developers.themoviedb.org/3/authentication/validate-request-token
func (tmdb *TMDb) GetAuthValidateToken(token, user, password string) (*AuthenticationToken, error) {
var validToken AuthenticationToken
uri := fmt.Sprintf("%s/authentication/token/validate_with_login?api_key=%s&request_token=%s&username=%s&password=%s", baseURL, tmdb.apiKey, token, user, password)
result, err := getTmdb(uri, &validToken)
return result.(*AuthenticationToken), err
}
// GetAuthSession generates a session id for user based authentication
// https://developers.themoviedb.org/3/authentication/create-session
func (tmdb *TMDb) GetAuthSession(token string) (*AuthenticationSession, error) {
var session AuthenticationSession
uri := fmt.Sprintf("%s/authentication/session/new?api_key=%s&request_token=%s", baseURL, tmdb.apiKey, token)
result, err := getTmdb(uri, &session)
return result.(*AuthenticationSession), err
}
// GetAuthGuestSession generates a valid request token for user based authentication
// https://developers.themoviedb.org/3/authentication/create-guest-session
func (tmdb *TMDb) GetAuthGuestSession() (*AuthenticationGuestSession, error) {
var session AuthenticationGuestSession
uri := fmt.Sprintf("%s/authentication/guest_session/new?api_key=%s", baseURL, tmdb.apiKey)
result, err := getTmdb(uri, &session)
return result.(*AuthenticationGuestSession), err
}