Sha256: 47c9a1e339e49dc946722a25884e303d63ab1d18b2c23fff951f9559ec5ee1aa
Contents?: true
Size: 1.05 KB
Versions: 16
Compression:
Stored size: 1.05 KB
Contents
package <%= package %> import ( "fmt" "net/http" ) type OAuth2Auth struct { // The authentication token AccessToken string } func (auth *OAuth2Auth) Authenticate(request *http.Request) { request.Header.Set("<%= auth.http_header %>", auth.AccessToken) } // SetExistingTokenAuth will use a previously acquired access token func (client *Client) SetExistingOAuth2Auth(accessToken string) { client.Authentication = &OAuth2Auth{ AccessToken: accessToken, } } // RevokeAuthToken will revoke the access token and remove authentication // from the client func (client *Client) RevokeAccessToken() error { httpClient := &http.Client{} req, err := http.NewRequest("POST", "<%= auth.revoke_url %>", nil) if err != nil { return err } if client.Authentication != nil { client.Authentication.Authenticate(req) } resp, err := httpClient.Do(req) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != 200 { return fmt.Errorf("Unable to revoke access token, HTTP %v", resp.StatusCode) } client.Authentication = nil return nil }
Version data entries
16 entries across 16 versions & 1 rubygems