2019-03-29 09:31:37 +04:00
// Yandex Disk File Pusher
// Copyright (c) 2019 Vladimir "fat0troll" Hodakov
package yandexv1
import (
"os"
"strings"
)
// authorize autorizes user and saves token to config
// Autorization made of two steps: providing user URL to create token and
// getting token from provided code
func authorize ( ) {
if ! checkAuth ( ) {
baseURL := "https://oauth.yandex.ru/authorize?response_type=code&client_id={{ client_id }}"
2019-03-30 04:31:31 +04:00
baseURL += "&device_id={{ device_id }}&device_name={{ device_name }}&force_confirm=yes"
2019-03-29 09:31:37 +04:00
2019-03-30 07:06:15 +04:00
baseURL = strings . Replace ( baseURL , "{{ client_id }}" , YandexAppID , 1 )
2019-03-29 09:31:37 +04:00
baseURL = strings . Replace ( baseURL , "{{ device_id }}" , c . Config . DeviceID , 1 )
2019-03-30 07:06:15 +04:00
baseURL = strings . Replace ( baseURL , "{{ device_name }}" , DefaultDeviceName , 1 )
2019-03-29 09:31:37 +04:00
dlog . Info ( ) . Msg ( "Please open in your browser this URL and authorize the app. After getting the code restart the app with -authCode param (see -h for details)." )
dlog . Info ( ) . Msgf ( "Auth URL: %s" , baseURL )
os . Exit ( 0 )
}
}
// checkAuth detects if we have authorized already
func checkAuth ( ) bool {
2019-03-30 07:06:15 +04:00
return c . Config . Token . AccessToken != ""
2019-03-29 09:31:37 +04:00
}