Project

Profile

Help

Story #9115

Updated by pulpbot over 2 years ago

 

 **Ticket moved to GitHub**: "pulp/pulp_container/491":https://github.com/pulp/pulp_container/issues/491 




 ---- 


 Allow the user to login to the registry with API tokens or a password.  

 ``` 
 podman login -u ${username} -p ${apitoken} 
 podman login -u ${username} -p ${password} 
 ``` 

 Approach 1 
 ========== 
 Define a custom authentication by subclassing the DRF's BaseAuthentication class. 
 The code flow will use most of the logic defined in the BasicAuthentication class. It will first try authenticate the current user against provided credentials as username and password and in case of failure it will then look to authenticate the    user against provided token. If the provided token is associated to the current user the authentication should succeed. 

 ``` 
 class LoginView(APIView): 

     authentication_classes = (CustomBasicAuthentication, JWTTokenAuthentication)  
    .... 
 ``` 

 Approach 2 
 ========== 
 Define a custom authentication class that will authenticate the current user against provided token. If the provided token is associated to the current user the authentication should succeed. 

 The authentication schemes are defined as a list of classes. REST framework will attempt to authenticate with each class in the list, and will set request.user and request.auth using the return value of the first class that successfully authenticates. 

 This custom authentication class(es) can be defined globally in DRF settings or can be used per view/viewset basis by explicitly specifying it in the view as follows: 

 ``` 
 class LoginView(APIView): 

     authentication_classes = (BasicAuthentication, TokenAPIAuthentication, JWTTokenAuthentication)  
    .... 
 ``` 

 In this case it will suffice to define it in the affected views. 

Back