https://github.com/ulbora/go-oauth2-client
A client for handling OAuth2 in a golang application
https://github.com/ulbora/go-oauth2-client
Last synced: about 1 month ago
JSON representation
A client for handling OAuth2 in a golang application
- Host: GitHub
- URL: https://github.com/ulbora/go-oauth2-client
- Owner: Ulbora
- License: agpl-3.0
- Created: 2017-08-12T18:14:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T01:40:52.000Z (about 5 years ago)
- Last Synced: 2025-01-26T13:22:00.890Z (3 months ago)
- Language: Go
- Size: 23.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-oauth2-client
==============Mockable Go OAuth2 client for access a OAuth2 Server from a golang application
# Installation
```
$ go get github.com/Ulbora/go-oauth2-client```
# Usage
## Auth Code Grant Type
### Auth Code Authorize
```
var a AuthCodeAuthorize
a.ClientID = "211"
a.OauthHost = "http://localhost:3000"
a.RedirectURI = "http:/localhost/token"
a.Scope = "write"
a.State = "12345"
res := a.AuthCodeAuthorizeUser()
```### Auth Code Token
```
var tn AuthCodeToken
tn.OauthHost = "http://localhost:3000"
tn.ClientID = "403"
tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
tn.Code = "yfgk5mj481QSl46n2zIZGl"
tn.RedirectURI = "http://www.google.com"
token := tn.AuthCodeToken()```
### Auth Code Refresh
```
var tn AuthCodeToken
tn.OauthHost = "http://localhost:3000"
tn.ClientID = "403"
tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
tn.RefreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjb2RlIiwidXNlcklkIjoia2VuIiwiY2xpZW50SWQiOjQwMywiaWF0IjoxNTAyNDE4NDQ1LCJ0b2tlblR5cGUiOiJyZWZyZXNoIiwiZXhwIjoxNTAyNDU0NDQ1LCJpc3MiOiJVbGJvcmEgT2F1dGgyIFNlcnZlciJ9.7rJPyXkVppTS_4_b3K8nUdnnrjmZI0R69_F7ii5_ueA"
token := tn.AuthCodeRefreshToken()```
## Implicit Grant Type### Implicit Authorize
```
var a ImplicitAuthorize
a.ClientID = "403"
a.OauthHost = "http://localhost:3000"
a.RedirectURI = "http://www.google.com"
a.Scope = "read"
a.State = "12345"
res := a.ImplicitAuthorize()```
## Client Credentials Grant Type### Client Credentials Token
```
var tn ClientCredentialsToken
tn.OauthHost = "http://localhost:3000"
tn.ClientID = "403"
tn.Secret = "554444vfg55ggfff22454sw2fff2dsfd"
token := tn.ClientCredentialsToken()```
## Password Grant Type
Not supported## Returned Token for grant types Auth Code, Refresh, and Client Credentials
```
type Token struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
ErrorReturned string `json:"error"`
}
```## Returned by Implicit
Implicit grand type calls the redirect URI and passes the token as a query parm.