Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create Authorizer (and client) without doing authorization in Go? #134

Closed
MaxCCC opened this issue Aug 21, 2020 · 4 comments
Closed

Comments

@MaxCCC
Copy link

MaxCCC commented Aug 21, 2020

I use javascript (frontend) to do the authorization. Now I want to use Go as backend and use this client to do API calls against the Spotify API.

In this example: https://github.com/zmb3/spotify/blob/master/examples/authenticate/authcode/authenticate.go you do the authentication and stuff in go.

How can I initialize auth without doing the newAuthorization in Go?

client := auth.NewClient(tok)

Currently I have it working but I still need to define the callback URL in the auth section while I would think it's unnecessary in my case:

var (
	auth  = spotify.NewAuthenticator(redirectURI, spotify.ScopeUserReadPrivate)
	ch    = make(chan *spotify.Client)
	state = "abc123"
)
@fabstu
Copy link

fabstu commented Oct 13, 2020

What happens if you pass an empty string to NewAuthenticator?

By the way, #123 shows how you can pass a pre-initialized http client into this library. You could just initialize yours by creating the client, setting up OAuth2 on it and passing the created http client in.

@kimtore
Copy link

kimtore commented Apr 23, 2021

Pardon me for necro-ing this issue but I believe this might be useful.
This was solved for my Go client, which uses an oauth2 token coming from a file on disk.
All you need is the oauth2.Token structure with the data. From https://github.com/ambientsound/visp/blob/5d5f7fd9feea2c2bbe82ba1d022fdfd5702c7578/prog/api.go#L29:

token := &oauth2.Token{ ... (fill in token from your Javascript frontend) ... }
httpClient := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(token))
spotifyClient := spotify.NewClient(httpClient)

@bretanac93
Copy link
Contributor

bretanac93 commented Oct 16, 2021

This issue has been stalling here for quite some time, but anyways can be helpful I just opened this PR #172 that showcases this use case.

@strideynet
Copy link
Collaborator

I'm going to go ahead and close as @bretanac93's demo shows this. If this re-occurs, please open a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants