diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/auth.go | 4 | ||||
-rw-r--r-- | service/service.go | 24 |
2 files changed, 16 insertions, 12 deletions
diff --git a/service/auth.go b/service/auth.go index e9bec38..38c0a43 100644 --- a/service/auth.go +++ b/service/auth.go @@ -40,12 +40,12 @@ func (s *authService) getClient(ctx context.Context) (c *mastodon.Client, err er if err != nil { return nil, ErrInvalidSession } - client, err := s.appRepo.Get(session.InstanceURL) + client, err := s.appRepo.Get(session.InstanceDomain) if err != nil { return } c = mastodon.NewClient(&mastodon.Config{ - Server: session.InstanceURL, + Server: client.InstanceURL, ClientID: client.ClientID, ClientSecret: client.ClientSecret, AccessToken: session.AccessToken, diff --git a/service/service.go b/service/service.go index 5181475..bb03c26 100644 --- a/service/service.go +++ b/service/service.go @@ -9,7 +9,6 @@ import ( "mime/multipart" "net/http" "net/url" - "path" "strings" "mastodon" @@ -64,14 +63,18 @@ func NewService(clientName string, clientScope string, clientWebsite string, func (svc *service) GetAuthUrl(ctx context.Context, instance string) ( redirectUrl string, sessionID string, err error) { - if !strings.HasPrefix(instance, "https://") { - instance = "https://" + instance + var instanceURL string + if strings.HasPrefix(instance, "https://") { + instanceURL = instance + instance = strings.TrimPrefix(instance, "https://") + } else { + instanceURL = "https://" + instance } sessionID = util.NewSessionId() err = svc.sessionRepo.Add(model.Session{ - ID: sessionID, - InstanceURL: instance, + ID: sessionID, + InstanceDomain: instance, }) if err != nil { return @@ -85,7 +88,7 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) ( var mastoApp *mastodon.Application mastoApp, err = mastodon.RegisterApp(ctx, &mastodon.AppConfig{ - Server: instance, + Server: instanceURL, ClientName: svc.clientName, Scopes: svc.clientScope, Website: svc.clientWebsite, @@ -96,9 +99,10 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) ( } app = model.App{ - InstanceURL: instance, - ClientID: mastoApp.ClientID, - ClientSecret: mastoApp.ClientSecret, + InstanceDomain: instance, + InstanceURL: instanceURL, + ClientID: mastoApp.ClientID, + ClientSecret: mastoApp.ClientSecret, } err = svc.appRepo.Add(app) @@ -136,7 +140,7 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *masto return } - app, err := svc.appRepo.Get(session.InstanceURL) + app, err := svc.appRepo.Get(session.InstanceDomain) if err != nil { return } |