@@ -14,17 +14,18 @@ import (
1414// New takes 3 parameters all from the Cognito console:
1515// - The client ID
1616// - The client secret
17- // - The base URL for your servcice , either a custom domain or cognito pool based URL
17+ // - The base URL for your service , either a custom domain or cognito pool based URL
1818// You need to ensure that the source login URL is whitelisted as a login page in the client configuration in the cognito console.
19- // GOTH does not provide a full token logout, to do that you need to do it in your code. If you donot perform a fuil logout thee
20- // existing token will be used on a login and the the user won't be prompted until after expiry.
19+ // GOTH does not provide a full token logout, to do that you need to do it in your code.
20+ // If you do not perform a full logout their existing token will be used on a login and the user won't be prompted to login until after expiry.
2121// To perform a logout
2222// - Destroy your session (or however else you handle the logout internally)
2323// - redirect to https://CUSTOM_DOMAIN.auth.us-east-1.amazoncognito.com/logout?client_id=clinet_id&logout_uri=http://localhost:8080/
2424// (or whatever your login/start page is).
25- // - Note that this page needs to be whitelabeled as a logout page in the cognito console as well.
25+ // - Note that this page needs to be white-labeled as a logout page in the cognito console as well.
2626
2727// This is based upon the implementation for okta
28+
2829type Provider struct {
2930 ClientKey string
3031 Secret string
@@ -53,7 +54,7 @@ func NewCustomisedURL(clientID, secret, callbackURL, authURL, tokenURL, issuerUR
5354 ClientKey : clientID ,
5455 Secret : secret ,
5556 CallbackURL : callbackURL ,
56- providerName : "aws " ,
57+ providerName : "cognito " ,
5758 issuerURL : issuerURL ,
5859 profileURL : profileURL ,
5960 }
@@ -160,38 +161,60 @@ func newConfig(provider *Provider, authURL, tokenURL string, scopes []string) *o
160161 return c
161162}
162163
164+ // userFromReader
165+ // These are the standard cognito attributes
166+ // from: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
167+ // all attributes are optional
168+ // it is possible for there to be custom attributes in cognito, but they don't seem to be passed as in the claims
169+ // all the standard claims are mapped into the raw data
163170func userFromReader (r io.Reader , user * goth.User ) error {
164171 u := struct {
165- Name string `json:"name"`
166- Email string `json:"email"`
167- FirstName string `json:"given_name"`
168- LastName string `json:"family_name"`
169- NickName string `json:"nickname"`
170- ID string `json:"sub"`
171- Locale string `json:"locale"`
172- ProfileURL string `json:"profile"`
173- Username string `json:"preferred_username"`
174- Zoneinfo string `json:"zoneinfo"`
172+ ID string `json:"sub"`
173+ Address string `json:"address"`
174+ Birthdate string `json:"birthdate"`
175+ Email string `json:"email"`
176+ EmailVerified string `json:"email_verified"`
177+ FirstName string `json:"given_name"`
178+ LastName string `json:"family_name"`
179+ MiddleName string `json:"middle_name"`
180+ Name string `json:"name"`
181+ NickName string `json:"nickname"`
182+ Locale string `json:"locale"`
183+ PhoneNumber string `json:"phone_number"`
184+ PictureURL string `json:"picture"`
185+ ProfileURL string `json:"profile"`
186+ Username string `json:"preferred_username"`
187+ UpdatedAt string `json:"updated_at"`
188+ WebSite string `json:"website"`
189+ Zoneinfo string `json:"zoneinfo"`
175190 }{}
176191
177192 err := json .NewDecoder (r ).Decode (& u )
178193 if err != nil {
179194 return err
180195 }
181196
197+ // Ensure all standard claims are in the raw data
182198 rd := make (map [string ]interface {})
183- rd ["ProfileURL" ] = u .ProfileURL
199+ rd ["Address" ] = u .Address
200+ rd ["Birthdate" ] = u .Birthdate
184201 rd ["Locale" ] = u .Locale
202+ rd ["MiddleName" ] = u .MiddleName
203+ rd ["PhoneNumber" ] = u .PhoneNumber
204+ rd ["PictureURL" ] = u .PictureURL
205+ rd ["ProfileURL" ] = u .ProfileURL
206+ rd ["UpdatedAt" ] = u .UpdatedAt
185207 rd ["Username" ] = u .Username
186- rd ["Zoneinfo" ] = u .Zoneinfo
208+ rd ["WebSite" ] = u .WebSite
209+ rd ["EmailVerified" ] = u .EmailVerified
187210
188211 user .UserID = u .ID
189212 user .Email = u .Email
190213 user .Name = u .Name
191214 user .NickName = u .NickName
192215 user .FirstName = u .FirstName
193216 user .LastName = u .LastName
194-
217+ user . AvatarURL = u . PictureURL
195218 user .RawData = rd
196219
197220 return nil
0 commit comments