Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/utils/oauth2/client/client.go
akuma06 03ea72595d OAuth API [done] (#1275)
* Initial Commit for OAuth API

This builds and run and return the right error.
Need to test it and then adding all users as possible client

* Added mising dependency

* just compile already...

* Fixing template test

* Imrpovements

Moved db stuff in models
Added some tests
Added form in modpanel to add/update a client
Added controllers for add/update of client

* Added Forms + speed improvements

Controller oauth client listing + html
Controller oauth client delete + messages
Messages on comment delete
New ES config that disable ES if set to false. Improve load speed on local development
Fix a load config bug
Fix index admin & translation string sign_out broken by @ewhal

* Sanitize empty strig in form array + css

Multiple empty array of strings are sanitized for the oauth client create form
Added some css for the form display

* Upload and Create form works

* Fix splitting response types

* Removing required on secret when updating

* fix travis error

* Fix travis template test

* Update dependency

* Moved to jinzhu instead of azhao

* randomizen secret on creation

* Final touch on oath api

improved display name
fix grant form csrf
fix login csrf on oauth

* Fix gorm test

* fix template test

* Fixing deleted dependency issue

* Make travis faster

* Fix typo

* Fix csrf for api calls

* This shouldn't be exempt

* Removing hard coded hash

@ewhal Don't forget to replace the hash in tokens.go with another one

* Added an example on how to use OAuth middleware

* Renamed fosite utils to oauth2 utils
2017-07-28 13:46:40 +10:00

123 lignes
4,4 Kio
Go

package client
import (
"strings"
"github.com/ory/fosite"
)
// Client represents an OAuth 2.0 Client.
//
// swagger:model oauthClient
type Client struct {
// ID is the id for this client.
ID string `json:"id" gorethink:"id"`
// Name is the human-readable string name of the client to be presented to the
// end-user during authorization.
Name string `json:"client_name" gorethink:"client_name"`
// Secret is the client's secret. The secret will be included in the create request as cleartext, and then
// never again. The secret is stored using BCrypt so it is impossible to recover it. Tell your users
// that they need to write the secret down as it will not be made available again.
Secret string `json:"client_secret,omitempty" gorethink:"client_secret"`
// RedirectURIs is an array of allowed redirect urls for the client, for example: http://mydomain/oauth/callback .
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`
// GrantTypes is an array of grant types the client is allowed to use.
//
// Pattern: client_credentials|authorize_code|implicit|refresh_token
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`
// ResponseTypes is an array of the OAuth 2.0 response type strings that the client can
// use at the authorization endpoint.
//
// Pattern: id_token|code|token
ResponseTypes []string `json:"response_types" gorethink:"response_types"`
// Scope is a string containing a space-separated list of scope values (as
// described in Section 3.3 of OAuth 2.0 [RFC6749]) that the client
// can use when requesting access tokens.
//
// Pattern: ([a-zA-Z0-9\.]+\s)+
Scope string `json:"scope" gorethink:"scope"`
// Owner is a string identifying the owner of the OAuth 2.0 Client.
Owner string `json:"owner" gorethink:"owner"`
// PolicyURI is a URL string that points to a human-readable privacy policy document
// that describes how the deployment organization collects, uses,
// retains, and discloses personal data.
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`
// TermsOfServiceURI is a URL string that points to a human-readable terms of service
// document for the client that describes a contractual relationship
// between the end-user and the client that the end-user accepts when
// authorizing the client.
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`
// ClientURI is an URL string of a web page providing information about the client.
// If present, the server SHOULD display this URL to the end-user in
// a clickable fashion.
ClientURI string `json:"client_uri" gorethink:"client_uri"`
// LogoURI is an URL string that references a logo for the client.
LogoURI string `json:"logo_uri" gorethink:"logo_uri"`
// Contacts is a array of strings representing ways to contact people responsible
// for this client, typically email addresses.
Contacts []string `json:"contacts" gorethink:"contacts"`
// Public is a boolean that identifies this client as public, meaning that it
// does not have a secret. It will disable the client_credentials grant type for this client if set.
Public bool `json:"public" gorethink:"public"`
}
func (c *Client) GetID() string {
return c.ID
}
func (c *Client) GetRedirectURIs() []string {
return c.RedirectURIs
}
func (c *Client) GetHashedSecret() []byte {
return []byte(c.Secret)
}
func (c *Client) GetScopes() fosite.Arguments {
return fosite.Arguments(strings.Split(c.Scope, " "))
}
func (c *Client) GetGrantTypes() fosite.Arguments {
// https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
//
// JSON array containing a list of the OAuth 2.0 Grant Types that the Client is declaring
// that it will restrict itself to using.
// If omitted, the default is that the Client will use only the authorization_code Grant Type.
if len(c.GrantTypes) == 0 {
return fosite.Arguments{"authorization_code"}
}
return fosite.Arguments(c.GrantTypes)
}
func (c *Client) GetResponseTypes() fosite.Arguments {
// https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
//
// <JSON array containing a list of the OAuth 2.0 response_type values that the Client is declaring
// that it will restrict itself to using. If omitted, the default is that the Client will use
// only the code Response Type.
if len(c.ResponseTypes) == 0 {
return fosite.Arguments{"code"}
}
return fosite.Arguments(c.ResponseTypes)
}
func (c *Client) GetOwner() string {
return c.Owner
}
func (c *Client) IsPublic() bool {
return c.Public
}