package client import ( "fmt" "net/url" "strings" "somehole.com/service/oauth2/session" ) type AuthorizationUrl struct { *Client *session.Session ResponseType string } func NewAuthorizationUrl(client *Client, id session.SessionId, responseType string) (url *AuthorizationUrl, err error) { ses, ok := client.sessions[id] if !ok { err = fmt.Errorf("no session found") } url = &AuthorizationUrl{ Client: client, Session: ses, ResponseType: responseType, } return } func (a *AuthorizationUrl) Url() *url.URL { v := url.Values{ "response_type": {a.ResponseType}, "client_id": {a.ClientId}, "redirect_uri": {a.RedirectUri}, "scope": {strings.Join(a.Scopes, " ")}, "state": {string(a.State)}, } return &url.URL{ Scheme: "https", Host: a.Host, Path: a.AuthorizationUrlPath, RawQuery: v.Encode(), } } func (a *AuthorizationUrl) String() string { return a.Url().String() }