示例#1
0
        public async Task ConnectWebApi(bool keepRefreshToken = true)
        {
            _securityStore = SecurityStore.Load(pluginDirectory);

            AuthorizationCodeAuth auth = new AuthorizationCodeAuth(_securityStore.ClientId, _securityStore.ClientSecret, "http://localhost:4002", "http://localhost:4002",
                                                                   Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative | Scope.UserReadCurrentlyPlaying | Scope.UserReadPlaybackState | Scope.UserModifyPlaybackState | Scope.Streaming | Scope.UserFollowModify);


            if (_securityStore.HasRefreshToken && keepRefreshToken)
            {
                Token token = await auth.RefreshToken(_securityStore.RefreshToken);

                _spotifyApi = new SpotifyWebAPI()
                {
                    TokenType = token.TokenType, AccessToken = token.AccessToken
                };
            }
            else
            {
                auth.AuthReceived += async(sender, payload) =>
                {
                    auth.Stop();
                    Token token = await auth.ExchangeCode(payload.Code);

                    _securityStore.RefreshToken = token.RefreshToken;
                    _securityStore.Save(pluginDirectory);
                    _spotifyApi = new SpotifyWebAPI()
                    {
                        TokenType = token.TokenType, AccessToken = token.AccessToken
                    };
                };
                auth.Start();
                auth.OpenBrowser();
            }
        }
示例#2
0
        public static SecurityStore Load(string pluginDir = null)
        {
            if (new FileInfo(pluginDir + "\\security.store").Exists)
            {
                return(JsonConvert.DeserializeObject <SecurityStore>(File.ReadAllText(pluginDir + "\\security.store")));
            }
            //Including personal ClientID and Secret
            //May remove if potential App/API usage gets out of hand
            SecurityStore _securityStore = new SecurityStore();

            _securityStore.ClientId     = "41544e27545e4196bdfb6ff3c90d4451";
            _securityStore.ClientSecret = "c575cd3b2a2347eb846b28f35d541ace";
            return(_securityStore);
        }