Code Monkey home page Code Monkey logo

cordova-spotify-oauth's Introduction

Cordova Spotify OAuth Plugin

Greenkeeper badge Travis

Easy Spotify authentication for Apache Cordova / PhoneGap apps

API Documentation

Features

This plugin provides a simple way of authenticating a user with the Spotify API using the authorization code flow.

The plugin uses SFSafariViewController and Chrome Custom Tabs, if available. This also means it will only work on iOS 9 and above (but this shouldn't be a problem anymore).

Examples

The plugin consists of two functions clobbered onto cordova.plugins.spotifyAuth.

Log in

const config = {
  clientId: "<SPOTIFY CLIENT ID>",
  redirectUrl: "<REDIRECT URL, MUST MATCH WITH AUTH ENDPOINT AND SPOTIFY DEV CONSOLE>",
  scopes: ["streaming"], // see Spotify Dev console for all scopes
  tokenExchangeUrl: "<URL OF TOKEN EXCHANGE HTTP ENDPOINT>",
  tokenRefreshUrl: "<URL OF TOKEN REFRESH HTTP ENDPOINT>",
};

cordova.plugins.spotifyAuth.authorize(config)
  .then(({ accessToken, expiresAt }) => {
    console.log(`Got an access token, its ${accessToken}!`);
    console.log(`Its going to expire in ${expiresAt - Date.now()}ms.`);
  });

Log out

cordova.plugins.spotifyAuth.forget();

Installation

cordova plugin add cordova-spotify-oauth

Usage

The plugin implements the OAuth Authorization Code flow for the Spotify API. This allows you to obtain access and refresh tokens for user related-actions (such as viewing and modifying their library, streaming tracks via the SDKs, etc.). Therefore, additional preparation in addition to installing the plugin is required.

Protocol registration

The plugin uses custom URL schemes (universal links support will follow) to redirect back from the browser into the app.

You need to register the callback protocol inside the App Info.plist so that iOS knows which app to start when it is redirected when the authentication is done. If you want to use Chrome Custom Tabs (optional, but 110% nice), you must also register the URL scheme and path you will be redirected to within the AndroidManifest.xml file.

Take a look at this repository to see how it's done for both cases.

Spotify Developer Registration

You need to register your custom redirect URL within the Spotify Developer console. Make sure you register the exact value you use within your code (including trailing slashes, etc.).

Token Exchange Service

The authorization code flow requires server code for security. These come in the form of two HTTP endpoints, one for the auth code exchange, and the other one for access token refresh. The SDK will POST application/x-www-form-urlencoded data and expects JSON back. Ensure you have proper CORS config set up.

To easily implement them, we built a Serverless service for AWS Lambda over in the oauth-token-api folder. Make sure you install the Serverless Framework properly! To resolve the project dependencies, please use yarn as shown below before deploying the service.

For the execution of the functions to work you need to set some environmental configuration in the file oauth-token-api/.env

CLIENT_ID="<Your Spotify Client ID>"
CLIENT_SECRET="<Your Spotify Client Secret>"
CLIENT_CALLBACK_URL="<The callback url of your app>" # e.g. "festify-spotify://callback"
ENCRYPTION_SECRET="<Secret used to encrypt the refresh token - please generate>"

You can then deploy the functions like this:

cd oauth-token-api
yarn install
serverless deploy

The serverless CLI will then print the URL where the functions can be reached. These are the values needed for tokenExchangeUrl and tokenRefreshUrl.

JavaScript usage

Head over to the API Documentation.

Contributing

Pull requests are very welcome! Please use the gitmoji style for commit messages.

cordova-spotify-oauth's People

Contributors

alex96gm avatar greenkeeper[bot] avatar gregorymaertens avatar manuelsc avatar neolegends avatar tobika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cordova-spotify-oauth's Issues

Use of unresolved identifier 'SPTAuth'

Hello,
Hows it going.
I recently started getting this problem in XCode with this line of code
let auth = SPTAuth.defaultInstance()! //Error = Use of unresolved identifier 'SPTAuth'
this is inside the SPotifyOauthPlugin.swift file

I've tried all rebuilding the project in all the version of Xcode 9 and 10.
Then I installed Xcode 8 and converted the file from swift version 2 to 3 and then installed xcode 9 again and this did not fix the issue
Any idea of what it could be?

No Open Intent to Login on Spotify

No open Intend to Login on Spotify,
i writed code below:

const config = {
      refreshSafetyMargin: 60,
      clientId: '<<MY CLIENT ID>>',
      redirectUrl: 'myapp://callback',
      scopes: ['streaming', 'playlist-read-private', 'user-read-email', 'user-read-private'],
      tokenExchangeUrl: 'https://myapp.herokuapp.com/exchange',
      tokenRefreshUrl: 'https://myapp.herokuapp.com/refresh',
};
cordova.plugins.spotifyAuth.authorize(config)

the method authorize return the error "auth_failed" on subscribe.

already checked clientId, CLIENT_ID, CLIENT_SECRET and CLIENT_CALLBACK_URL

Ios - SpotifyOAuthPlugin.swift - observer not seems to be working

the plugin works well up to auth process after auth the SFSafariViewController stays in the spotify redirect page does not
dismiss the SFSafariViewController.

    var observer: NSObjectProtocol?
    observer = NotificationCenter.default.addObserver(
        forName: NSNotification.Name.CDVPluginHandleOpenURL,
        object: nil,
        queue: nil
    ) { note in
        let url = note.object as! URL
        guard url.absoluteString.contains("code") else { return }
        
        svc.presentingViewController!.dismiss(animated: true, completion: nil)
        NotificationCenter.default.removeObserver(observer!)
        self.currentNsObserver = nil
        self.currentCommand = nil

        let res = CDVPluginResult(
            status: CDVCommandStatus_OK,
            messageAs: [
                "code": url["code"]
            ]
        )
        self.commandDelegate.send(res, callbackId: command.callbackId)
    }

Plugin crashes before showing login screen

Hi there,

I tried to use your plugin and it crashes on Android before the Login screen appears. I entered all the neccesary information. Here is my config ->

clientId: "15dd21d1356notmyrealId", redirectUrl: "http://localhost:3000/callback", scopes: ["streaming"], tokenExchangeUrl: "http://mysubdomain.herokuapp.com/swap", tokenRefreshUrl: "http://mysubdomain.herokuapp.com/refresh",

The error I'm getting is Uncaught (in promise) auth_failed: Received authentication response of invalid type error

Do you have any idea what the reason might be?

Thanks,
Andi

Failed to load with capacitor

Has anyone tried and installed it with Ionic Capacitor? I'm trying to open it on ios, but it gives me this error
no such file or directory, stat '/Users/user/ionic/suggestion/node_modules/cordova-spotify-oauth/src/ios/spotify-sdk/SpotifyAuthentication.framework'

Any suggestions? Thanks!

Failed to install since latest merge

Hi i am hoping someone can help. First of all thanks for updating the plugin with the removal of the legacy Spotify SDK as this is the best plugin out there.

So it seems as though since the latest merge to resolve the legacy SDK issue i am no longer able to install the plugin. I have even tried on a brand new empty cordova project and i get the same error message.

I am currently running:
Cordova 8.1.2 ([email protected])
iOS 5.1.1

The issue i am receiving seems to reference install-ios.sh which i thought was removed? Here is the output of the terminal whenever i call 'cordova plugins add cordova-spotify-oauth'

Dean-Air:cordovatestproject duffdean$ cordova plugins add cordova-spotify-oauth
Installing "cordova-spotify-oauth" for ios
Dependent plugin "es6-promise-plugin" already installed on ios.
Plugin dependency "[email protected]" already fetched, using that version.
Dependent plugin "cordova-plugin-add-swift-support" already installed on ios.
Running command: /Users/duffdean/cordovatestproject/plugins/cordova-spotify-oauth/install-ios.sh /Users/duffdean/cordovatestproject
tar: Error opening archive: Unrecognized archive format
Failed to install 'cordova-spotify-oauth': Error: Hook failed with error code 1: /Users/duffdean/cordovatestproject/plugins/cordova-spotify-oauth/install-ios.sh
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:239:23
at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:864:24)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:890:30
at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1142:31)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:808:41)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:624:44
at runSingle (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:137:13)
at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:125:13)
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Hook failed with error code 1: /Users/duffdean/cordovatestproject/plugins/cordova-spotify-oauth/install-ios.sh

Any help would be greatly appreciated!

Thanks

HTTP status code 500

Hello,
when I try to authenticate everything looks fine and I also get redirected to the app but the token exchange function gives back a code 500.
Do you have an idea what could be the issue? I think I configured everything fine...

'auth_failed' error while trying to receive access token

Hi, I have been using your plugin in my project without problems until today, when I decided to test authorization after a long time of developing. I was surprised when instead of token I received error 'auth_failed'. After a few hours of evestigating, I decided to reject all possible mistakes and separated authorization into an individual project. And still, when I run the process I see how authorization view pop-ups, then after some time of loading it's hiding down and returns the error. Steps to reproduce the error (on base of this tutorial):

ionic start testspotifyauth blank
cd testspotifyauth
ionic cordova plugin add cordova-spotify-oauth
ionic cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME= testspotifyauth

home.page.ts:

import { Component } from '@angular/core';
import { NavController } from '@ionic/angular';
 
declare var cordova: any;
@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  result = {};
 
  constructor(public navCtrl: NavController) { }
 
  authWithSpotify() {
    const config = {
      clientId: "my spotify id",
      redirectUrl: "whatever://callback",
      scopes: ["streaming", "playlist-read-private", "user-read-email", "user-read-private"],
      tokenExchangeUrl: "https://tmdj-oauth-server.herokuapp.com/exchange",
      tokenRefreshUrl: "https://tmdj-oauth-server.herokuapp.com/refresh",
    };
 
    cordova.plugins.spotifyAuth.authorize(config)
      .then(({ accessToken, encryptedRefreshToken, expiresAt }) => {
        this.result = { access_token: accessToken, expires_in: expiresAt, ref: encryptedRefreshToken };
        console.log(this.result);
      });
  }
}

home.page.html:

<ion-header>
  <ion-toolbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <div class="ion-padding">
    The world is your oyster.
    <ion-button (click)="authWithSpotify()">Auth</ion-button>
  </div>
</ion-content>

I'm not sure where this error comes from, but mb it appeared after I updated my android device.
Model: SM-N960F
Android version: 9

[Question] Use with other oAuth providers?

Hi everyone!

This is a beautiful oAuth implementation, I love how easy it was to implement and use in Cordova! Thanks for making this. Do you guys ever think about white labeling the oAuth functionality and use it for other oAuth providers? I think it could be really helpful. Just curious. If so, I'd love to help write docs or contribute some examples. I got this working in a VueJS cordova app and it was seamless!

error in auth: 404 - ionic://localhost is not allowed by Access-Control-Allow-Origin

Upon starting the mobile app (built in Cordova) in XCode we get the following error in the Safari Developer View and we had been getting those errors even before when the app functionality was in no way hindered.

Failed to load resource - the server responded with a status of 404() - ionic://localhost/plugins/cordova-spotify-oauth/www/build/spotify-oauth.min.js.map
Failed to load resource - the server responded with a status of 404() - ionic://localhost/plugins/cordova-spotify/www/build/cordova-spotify.min.js.map

2,5 months ago approximately the app functionality from Spotify stopped working and now I am wondering if it is possible that it has to do with these errors or if it depends on Spotify upgrading or changing their API.

The code for playing the button in app.js does not even catch the error for the unreturned Promise or do we get any other console log besides "Play button pressed" and "In try clause". It never reaches the spotify play function.

Any idea what might be happening here?

function spotify_play ( element, accessToken, expiresAt ) {
console.log('Inside spotify_play');
var spotify_uri = element.dataset.spotify_uri;
var spotify_state = element.dataset.spotify_state;
var spotify_pos = element.dataset.spotify_pos;
var play_src = './static/img/_ionicons_svg_ios-play.svg';
var pause_src = './static/img/_ionicons_svg_ios-pause.svg';
if ( spotify_state == "stopped" ) {
cordova.plugins.spotify.play(spotify_uri, {
clientId: spotify_client_id,
token: accessToken
})
$(element).attr('data-spotify_state','playing');
//Change to pausebutton image.
$(element).find('.play-image').attr('src', pause_src);
} else if ( spotify_state == "playing" ) {
var position = "";
cordova.plugins.spotify.getPosition()
.then(pos => $(element).attr('data-spotify_pos', pos))
.catch(() => console.log("Whoops, no track is playing right now."));
cordova.plugins.spotify.pause()
$(element).attr('data-spotify_state','paused');
//Change to playbutton image.
$(element).find('.play-image').attr('src', play_src);
} else if ( spotify_state == "paused" ) {
cordova.plugins.spotify.play(spotify_uri, {
clientId: spotify_client_id,
token: accessToken
},
spotify_pos
)
$(element).attr('data-spotify_state','playing');
//Change to pausebutton image.
$(element).find('.play-image').attr('src', pause_src);
}
}

$(document).on('click', '.spotify-play', function ( event ) {
console.log('Play button pressed.');
try{
console.log('In try clause');
cordova.plugins.spotifyAuth.authorize(config)
.then(({ accessToken, expiresAt }) => {
console.log('Promise returned');
console.log('Access Token: ', accessToken);
spotify_play( this, accessToken, expiresAt )
}).catch(function(error){
console.log(error);
});

We have been using Spotify Web-Api with authorization through access and refresh tokens and successfully using both of your plugins till about 2 months ago. Any help is greatly appreciated.

New Plugin install generates error: Failed to restore plugin

Background on the issue

When I attempt to install the plugin into a new cordova project, it is creating an error on install.

My Cordova version

Command I am running

cordova plugin add cordova-spotify-oauth

Expected results

  • Plugin should install without errors

Actual results

Adding cordova-spotify-oauth to package.json
Saved plugin info for "cordova-spotify-oauth" to config.xml
Failed to restore plugin "cordova-spotify-oauth" from config.xml. You might need to try adding it again. Error: Error: Cannot find module '../cordova/platform_metadata'

Additional notes

Thanks for putting this plugin together! You guys rock!!

Works in emulator, fails on real device

I have probably set up the callback wrong, because I do not really understand what value it should be set to, but...

I have set up a serverless-offline server on my own non-cloud server.
It has my refresh and exchange urls which point to the relevant endpoints on my domain.
But for redirectUrl, I have: http://localhost:8888/callback
This redirectUrl is a registered callback on my App in Spotify.

In the config.xml I have:

        <config-file parent="/*" target="res/values/strings.xml">
            <string name="com_spotify_sdk_redirect_scheme">http</string>
            <string name="com_spotify_sdk_redirect_host">localhost:8888/callback</string>
        </config-file>

Inside the <platform name="android"> tag.

When I run the emulator with cordova emulate android. It all works fine...

When I send the app-debug.apk to my phone, the Loading message appears, then a small animation seems to happen where it tries to load something on the screen, then it disappears.

Any ideas please?

Phonegap Build

Hi, i'm working with phonegap build and i get following error while creating a build:

Error - Plugin error (you probably need to remove plugin files from your app): 
Fetching plugin "cordova-spotify-oauth" via npm Installing "cordova-spotify-oauth" at "0.1.11" for ios 
Fetching plugin "es6-promise-plugin" via npm Installing "es6-promise-plugin" at "4.2.2" for ios 
Fetching plugin "[email protected]" via npm Installing "cordova-plugin-add-swift-support" at "1.6.1" for ios 

Error during processing of action! Attempting to revert... Failed to install 'cordova-spotify-oauth': 

CordovaError: Uh oh! Cannot find framework 
"/private/tmp/gimlet/3178773/project/cordova/plugins/cordova-spotify-oauth/src/ios/spotify-sdk/SpotifyAuthentication.framework" for plugin cordova-spotify-oauth
in iOS platform at install 
(/private/tmp/gimlet/3178773/project/cordova/lib/plugman/pluginHandlers.js:109:48)
at ActionStack.process (/private/tmp/gimlet/3178773/project/cordova/node_modules/cordova-common/src/ActionStack.js:56:25) at PluginManager.doOperation 
(/private/tmp/gimlet/3178773/project/cordova/node_modules/cordova-common/src/PluginManager.js:114:20) at PluginManager.addPlugin 
(/private/tmp/gimlet/3178773/project/cordova/node_modules/cordova-common/src/PluginManager.js:144:17) at Api.addPlugin 
(/private/tmp/gimlet/3178773/project/cordova/Api.js:234:10) at handleInstall 
(/usr/local/lib/node_modules/pgb-plugman-151/node_modules/pgb-cordova-lib/src/plugman/install.js:594:10) at /usr/local/lib/node_modules/pgb-plugman-151/node_modules/pgb-cordova-lib/src/plugman/install.js:357:28 at _fulfilled
(/usr/local/lib/node_modules/pgb-plugman-151/node_modules/q/q.js:787:54) at
/usr/local/lib/node_modules/pgb-plugman-151/node_modules/q/q.js:816:30 at
Promise.promise.promiseDispatch (/usr/local/lib/node_modules/pgb-plugman-151/node_modules/q/q.js:749:13) 
Uh oh! Cannot find framework "/private/tmp/gimlet/3178773/project/cordova/plugins/cordova-spotify-oauth/src/ios/spotify-sdk/SpotifyAuthentication.framework" 
for plugin cordova-spotify-oauth in iOS platform

Anything i can do?

<gap:plugin name="cordova-spotify-oauth" source="npm" />

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

Universal links support

...is easy to implement and doesn‘t require much more config (from the plugin side) than custom protocols, as far as I remember.

Just gotta get around to implementing that.

Browser Support

Copied from email:

Hi


I have made a fork of your cordova-spotify-oauth plugin, so we can add browser support. (https://github.com/ThorvaldAagaard/cordova-spotify-oauth)

I think I have got it working, yet we need to test it and probably make some small adjustments

I have a small question, I hope you have time to answer about the plugin architecture

When I installed the plugin from my repo it failed because of a missing spotify-oauth.min.js. I can see it is generated locally but omittted in github, so can you explain how it is supposed to be generated during installation? (It is my first time building a plugin)


Best Regards

Thorvald

@ThorvaldAagaard

spotify-oauth.min.js missing from release?

Hello,

I'm trying to integrate this plugin, but when installing it, I'm getting this error:

`
Running command: MYROOT/plugins/cordova-spotify-oauth/install-ios.sh MYROOT

Error during processing of action! Attempting to revert...
Failed to install 'cordova-spotify-oauth': Error: Uh oh!
ENOENT: no such file or directory, open 'MYROOT/plugins/cordova-spotify-oauth/www/build/spotify-oauth.min.js'
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.readFileSync (fs.js:508:33)
at install (MYROOT/platforms/ios/cordova/lib/plugman/pluginHandlers.js:206:36)
etc...

Error: Uh oh!
ENOENT: no such file or directory, open 'MYROOT/plugins/cordova-spotify-oauth/www/build/spotify-oauth.min.js'

`

when looking at the release zip file it looks like it's missing there (i.e. www/build/spotify-oauth.min.js missing in the zip)
On TravisCI spotify-oauth.min.js is generated by webpack correctly.

Is the artifact not exported correctly into the archive?

Thanks!

References:
$ cordova --version
7.1.0
$ ionic --version
3.16.0

Fetching version 0.1.7 from this plugin

Login issue on ios with safari.

I'm using ionic 3 and using spotify oauth,
uts working on android ok but on ios is giving an issue after allow from spotify login popup then it wil not come back to app its showing something like this.
1589016667284
Please help me.

Handle changing scopes

Right now, if the scopes change, we do not automatically fall back to a full authorization, the user has to manually forget the cached credentials in order to get access to the new scopes.

Error using Ionic 5 / Cordova 9

After installing this plugin and when i try to authorize the user, i get this error in the console:

ERROR: Method 'getCode:' not defined in Plugin 'SpotifyOAuth'

This is the swift support version that i use in the project.
"cordova-plugin-add-swift-support": "2.0.2"

Any ideas how to solve this?

'auth_failed'. Potential local storage issue?

Environment Details:
Hardware: MacBok Air (2017)
Node: v6.11.4
Ionic: 3.18.0
Cordova: 7.1.0
Cordova-spotify-oauth: 0.1.10
Side menu template, scaffolded app.

Hi Guys, My AWS lambda functions are working fine and I can see they are returning the access token, however, I was receiving 'undefined' when trying to log it or bind it to the display for testing.

I put a catch on the cordova.plugins.spotifyAuth.authorize(config) call and was able to log the following error:

console.log:
            {"line":2,"column":5224,"sourceURL":"http://192.168.0.11:8101/plugins/cordova-spotify-oauth/www/build/spotify-oauth.min.js","name":"auth_failed","__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}

Having a look in the spotify-oauth.ts file, I can see that this error can be caused if the scopes arrays don't match (I believe I ruled this out quite quickly), or if there is no SpotifyOAuthData in localStorage (the line / column numbers seemed to match) ...

In the catch, I tried to carry out a window.localStorage.getItem('SpotifyOAuthData') and It doesn't look like any data has been persisted to the localStorage. I presumed then that this could be environmental and tested the same application under Windows using the Android emulator. The token was displayed on screen as expected...

I tested localStorage myself, in a similar way. I was able to set an Item and get the same item, displaying it on screen successfully using window.localStorage. I'm starting to believe it is an issue on the iOS plugin but I can't quiet pinpoint why the data is not being set.

I'm going to try a few more things tomorrow. But thought I'd post this to see if you guys had encountered any similar issues or had any ideas for resolution.

Any help appreciated.

App.ts

initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      const config = {
        clientId: "xxxxxxxx",
        redirectUrl: "vimana://callback",
        scopes: [], // have tried with 'streaming' and null.
        tokenExchangeUrl: "https://xxxxxxx-api.eu-central-1.amazonaws.com/dev/exchange",
        tokenRefreshUrl: "https://xxxxxxxxx-api.eu-central-1.amazonaws.com/dev/refresh",
      }

      cordova.plugins.spotifyAuth.authorize(config)
      .then(({ accessToken, expiresAt }) => {
        this.events.publish('spotify:tokensaved', accessToken, expiresAt);
      })
      .catch(error => {
        console.log(JSON.stringify(error));
      });

    });
  }`

Home.ts

export class HomePage {

  token: any;

  constructor(public events: Events, public navCtrl: NavController) {
    events.subscribe('spotify:tokensaved', (accessToken, expiresAt) => {
      // user and time are the same arguments passed in `events.publish(user, time)`
      console.log(accessToken);
      console.log(expiresAt);

      this.token = accessToken;

    });
  }

}

Home.html

<ion-content padding>
  Your token is: {{ token }}
</ion-content>

forget() doesn't logout user completely

Hello,

when calling forget(), it clears the auth data in local storage so the oauth can start again. However, since it uses native web views and cookies are not cleared, one faces the same issue as described by this user: spotify/ios-sdk#151
Basically the data from the previous user remains in the webview.

Is it possible to have a way to perform completely a logout?
=> clear the cookies? Not sure it's the best way with SFSafariWebView
=> open logout page for spotify auth (didn't find the URL). See https://github.com/OAuthSwift/OAuthSwift/wiki/Logout

Thanks!
Greg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.