https://github.com/loomnetwork/oauth2-noserver
Simplifying the oauth2 auth flow for desktop / cli apps that have no server side.
https://github.com/loomnetwork/oauth2-noserver
Last synced: 5 months ago
JSON representation
Simplifying the oauth2 auth flow for desktop / cli apps that have no server side.
- Host: GitHub
- URL: https://github.com/loomnetwork/oauth2-noserver
- Owner: loomnetwork
- License: mit
- Fork: true (nmrshll/oauth2-noserver)
- Created: 2017-10-13T09:53:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-13T15:58:17.000Z (over 8 years ago)
- Last Synced: 2023-07-27T22:19:34.850Z (almost 3 years ago)
- Language: Go
- Homepage:
- Size: 62.5 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oauth2ns: easy oauth2 for purely client side apps (desktop GUI, cli, mobile)
While oauth works fine for apps the have a server side, I personally find it a pain to use when developing simple desktop or cli applications.
That's why needed something to turn a complete oauth flow into a one-liner (well, that's clearly exaggerated, but it's barely more).
So here's how it works !
# Usage
On the web service that you want your app to authenticate into, register you app (aka client) to get a `client id` and a `client secret`.
**IMPORTANT**: you must set the redirection URL to `http://127.0.0.1:14565/oauth/callback` for this lib to function properly.
Here's an example of creating an app on bitbucket. The UI is usually similar on other web services.

This will give you the `client id` and `client secret` you need to authenticate your apps' users.
And then, from your Go program, authenticate your user like this :
[embedmd]:# (./example/example.go)
```go
package main
import (
"github.com/n-marshall/oauth2ns"
"golang.org/x/oauth2"
)
func main() {
conf := &oauth2.Config{
ClientID: "tRQ9V3cyLxHu3xXFWM", // also known as slient key sometimes
ClientSecret: "PZEU9ruk3eZxYvAeCRgS9YyYpAybLG4P", // also known as secret key
Scopes: []string{"account"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://bitbucket.org/site/oauth2/authorize",
TokenURL: "https://bitbucket.org/site/oauth2/access_token",
},
}
/*client := ...*/ _ = oauth2ns.Authorize(conf)
// use client.Get / client.Post for further requests, the token will automatically be there
}
```
The `AuthURL` and `TokenURL` can be found in the service's oauth documentation.