-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate user-pass login in favor of OAuth2 flow
See #53 and librespot-org/librespot#1308
- Loading branch information
Showing
8 changed files
with
149 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package session | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
log "github.com/sirupsen/logrus" | ||
"net" | ||
"net/http" | ||
) | ||
|
||
func NewOAuth2Server(ctx context.Context, callbackPort int) (int, chan string, error) { | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", callbackPort)) | ||
if err != nil { | ||
return 0, nil, fmt.Errorf("failed to listen: %w", err) | ||
} | ||
|
||
errCh := make(chan error, 1) | ||
resCh := make(chan string, 1) | ||
go func() { | ||
errCh <- http.Serve(lis, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | ||
resCh <- r.URL.Query().Get("code") | ||
_, _ = rw.Write([]byte("Go back to go-librespot!")) | ||
})) | ||
}() | ||
|
||
go func() { | ||
select { | ||
case <-ctx.Done(): | ||
_ = lis.Close() | ||
case err := <-errCh: | ||
if err != nil { | ||
log.WithError(err).Errorf("failed service oauth2 server") | ||
resCh <- "" | ||
} | ||
} | ||
}() | ||
|
||
return lis.Addr().(*net.TCPAddr).Port, resCh, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters