auth

Paddy 2015-12-14 Parent:4b68bac597b7

181:b7e685839a1b Go to Latest

auth/client/login.go

Break out scopes and events. This repo has gotten unwieldy, and there are portions of it that need to be imported by a large number of other packages. For example, scopes will be used in almost every API we write. Rather than importing the entirety of this codebase into every API we write, I've opted to move the scope logic out into a scopes package, with a subpackage for the defined types, which is all most projects actually want to import. We also define some event type constants, and importing those shouldn't require a project to import all our dependencies, either. So I made an events subpackage that just holds those constants. This package has become a little bit of a red-headed stepchild and is do for a refactor, but I'm trying to put that off as long as I can. The refactoring of our scopes stuff has left a bug wherein a token can be granted for scopes that don't exist. I'm going to need to revisit that, and also how to limit scopes to only be granted to the users that should be able to request them. But that's a battle for another day.

History
paddy@172 1 package client
paddy@172 2
paddy@172 3 import (
paddy@172 4 "code.secondbit.org/auth.hg"
paddy@181 5 "code.secondbit.org/scopes.hg/types"
paddy@172 6 )
paddy@172 7
paddy@172 8 func (c *Client) GetLogin(value string) (auth.Login, error) {
paddy@181 9 resp, err := c.Get("/logins/"+value, scopeTypes.Scopes{auth.ScopeLoginAdmin}.Strings(), nil)
paddy@172 10 if err != nil {
paddy@180 11 hErr, ok := err.(httpErrors)
paddy@180 12 if ok && hErr[0].Slug == auth.RequestErrNotFound {
paddy@180 13 return auth.Login{}, auth.ErrLoginNotFound
paddy@180 14 }
paddy@172 15 return auth.Login{}, err
paddy@172 16 }
paddy@172 17 if len(resp.Logins) < 1 {
paddy@172 18 return auth.Login{}, auth.ErrLoginNotFound
paddy@172 19 }
paddy@172 20 return resp.Logins[0], nil
paddy@172 21 }