@ -143,6 +143,7 @@ func main() {
ddoc , err := parseDiscoveryDoc ( configEndpoint )
ddoc , err := parseDiscoveryDoc ( configEndpoint )
if err != nil {
if err != nil {
log . Println ( fmt . Errorf ( "Failed to parse OIDC discovery document %s" , err ) )
fmt . Println ( err )
fmt . Println ( err )
return
return
}
}
@ -163,10 +164,16 @@ func main() {
state := randomState ( )
state := randomState ( )
http . HandleFunc ( "/" , func ( w http . ResponseWriter , r * http . Request ) {
http . HandleFunc ( "/" , func ( w http . ResponseWriter , r * http . Request ) {
log . Printf ( "%s %s" , r . Method , r . RequestURI )
if r . RequestURI != "/" {
http . NotFound ( w , r )
return
}
http . Redirect ( w , r , config . AuthCodeURL ( state ) , http . StatusFound )
http . Redirect ( w , r , config . AuthCodeURL ( state ) , http . StatusFound )
} )
} )
http . HandleFunc ( "/oauth2/callback" , func ( w http . ResponseWriter , r * http . Request ) {
http . HandleFunc ( "/oauth2/callback" , func ( w http . ResponseWriter , r * http . Request ) {
log . Printf ( "%s %s" , r . Method , r . RequestURI )
if r . URL . Query ( ) . Get ( "state" ) != state {
if r . URL . Query ( ) . Get ( "state" ) != state {
http . Error ( w , "state did not match" , http . StatusBadRequest )
http . Error ( w , "state did not match" , http . StatusBadRequest )
return
return
@ -189,13 +196,11 @@ func main() {
sts , err := credentials . NewSTSWebIdentity ( stsEndpoint , getWebTokenExpiry )
sts , err := credentials . NewSTSWebIdentity ( stsEndpoint , getWebTokenExpiry )
if err != nil {
if err != nil {
log . Println ( fmt . Errorf ( "Could not get STS credentials: %s" , err ) )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
return
return
}
}
// Uncomment this to use MinIO API operations by initializing minio
// client with obtained credentials.
opts := & minio . Options {
opts := & minio . Options {
Creds : sts ,
Creds : sts ,
BucketLookup : minio . BucketLookupAuto ,
BucketLookup : minio . BucketLookupAuto ,
@ -203,23 +208,40 @@ func main() {
u , err := url . Parse ( stsEndpoint )
u , err := url . Parse ( stsEndpoint )
if err != nil {
if err != nil {
log . Println ( fmt . Errorf ( "Failed to parse STS Endpoint: %s" , err ) )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
return
return
}
}
clnt , err := minio . NewWithOptions ( u . Host , opts )
clnt , err := minio . NewWithOptions ( u . Host , opts )
if err != nil {
if err != nil {
log . Println ( fmt . Errorf ( "Error while initializing Minio client, %s" , err ) )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
return
return
}
}
buckets , err := clnt . ListBuckets ( )
buckets , err := clnt . ListBuckets ( )
if err != nil {
if err != nil {
log . Println ( fmt . Errorf ( "Error while listing buckets, %s" , err ) )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
http . Error ( w , err . Error ( ) , http . StatusBadRequest )
return
return
}
}
creds , _ := sts . Get ( )
bucketNames := [ ] string { }
for _ , bucket := range buckets {
for _ , bucket := range buckets {
log . Println ( bucket )
log . Println ( fmt . Sprintf ( "Bucket discovered: %s" , bucket . Name ) )
bucketNames = append ( bucketNames , bucket . Name )
}
response := make ( map [ string ] interface { } )
response [ "credentials" ] = creds
response [ "buckets" ] = bucketNames
c , err := json . MarshalIndent ( response , "" , "\t" )
if err != nil {
http . Error ( w , err . Error ( ) , http . StatusInternalServerError )
return
}
}
w . Write ( c )
} )
} )
address := fmt . Sprintf ( "localhost:%v" , port )
address := fmt . Sprintf ( "localhost:%v" , port )